local H = require "packages/new_heg/util"
local HC = require "packages/new_hegcomplements/util"
local U = require "packages/utility/utility"
local extension = Package:new("jinheg")
extension.extensionName = "new_hegcomplements"
extension.game_modes_whitelist = { 'ex_heg_mode', 'mul_heg_mode' }

Fk:loadTranslationTable {
  ["jinheg"] = "<font color='purple'>官盗-晋</font>",
}

local simayi = General(extension, "tyt_hc_heg__n_simayif", "jinz", 3)

local quanbian = fk.CreateTriggerSkill{
  name = "tyt_hc__quanbian",
  anim_type = "drawcard",
  events = {fk.CardUsing, fk.CardResponding},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and player.phase ~= Player.NotActive and U.IsUsingHandcard(player, data)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local cids = target:getCardIds({Player.Hand,Player.Equip})
    local cards = room:getNCards(player.maxHp)
    local to_ex = U.askForExchange(player, "Top", "#tyt_hc__quanbian-card", cards, cids, "#tyt_hc__quanbian-exchange", 1)
    if #to_ex ~= 2 then return end
    local index = 0
    local cardA = table.find(cards, function (id)
      index = index + 1
      return table.contains(to_ex, id)
    end)
    local cardB = table.find(to_ex, function (id)
      return id ~= cardA
    end)
    table.remove(cards, index)
    table.insert(cards, index, cardB)
    U.swapCardsWithPile(target, cards, {cardA}, self.name, "Top", false, player.id)
  end,
}

local yingshi = fk.CreateTriggerSkill{
  name = "tyt_hc__yingshi",
  frequency = Skill.Compulsory,
  refresh_events = {fk.AfterCardsMove, fk.TurnStart, fk.MaxHpChanged, fk.EventAcquireSkill, fk.GeneralShown, fk.AfterDrawPileShuffle,
    }, --fk.AfterSkillEffect
  can_refresh = function(self, event, target, player, data)
    if not (player.phase ~= Player.NotActive and player:hasShownSkill(self)) then return end
    if event == fk.TurnStart or event == fk.MaxHpChanged then
      return player == target
    elseif event == fk.AfterCardsMove then
      for _, move in ipairs(data) do
        if move.toArea == Card.DrawPile then
          return true
        end
        for _, info in ipairs(move.moveInfo) do
          if info.fromArea  == Card.DrawPile then
            return true
          end
        end
      end
    elseif event == fk.AfterDrawPileShuffle then --event == fk.AfterSkillEffect FIXME:应该考虑那些直接在牌堆改顺序的技能，比如观星，询询
      return true
    elseif event == fk.EventAcquireSkill then
      return player == target and data == self
    elseif event == fk.GeneralShown then
      for _, v in pairs(data) do
        if table.contains(Fk.generals[v]:getSkillNameList(), self.name) then return true end
      end
    end
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    local oldcards, cards = U.getPrivateMark(player, "$tyt_hc__yingshi-turn"), room:getNCards(math.min(player.maxHp, #room.draw_pile))
    local notify = false
    if #oldcards ~= #cards then
      notify = true
    end
    if not notify then
      for i = 1, math.max(#oldcards,#cards), 1 do
        if oldcards[1] ~= cards[1] then
          notify = true
          break
        end
      end
    end
    if notify then
      if event == fk.TurnStart or event == fk.EventAcquireSkill or event == fk.GeneralShown then
        room:notifySkillInvoked(player, self.name)
        player:broadcastSkillInvoke(self.name)
      end
      U.setPrivateMark(player, "$tyt_hc__yingshi-turn", cards)
      local arg = table.concat(table.map(cards, function (cid)
        return Fk:getCardById(cid):toLogString()
      end), ",")
      room:doBroadcastNotify("GameLog", json.encode({
        type = "#tyt_hc__yingshi",
        arg = arg,
        toast = true,}), {player})
    end
  end,

  on_lose =function (self, player, is_death)
    player.room:setPlayerMark(player, "@[private]$tyt_hc__yingshi-turn", 0)
  end,
}

local yingshi_visible = fk.CreateVisibilitySkill{
  name = "#tyt_hc__yingshi_visible",
  card_visible = function (self, player, card)
    if card and player:hasShownSkill(yingshi) and table.contains(U.getPrivateMark(player, "$tyt_hc__yingshi-turn"), card.id) then
      return true
    end
  end,
}

local zhouting = fk.CreateActiveSkill{
  name = "tyt_hc__zhouting",
  anim_type = "offensive",
  frequency = Skill.Limited,
  card_num = 0,
  card_filter = Util.FalseFunc,
  target_num = 0,
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryGame) == 0
  end,
  on_use = function(self, room, effect)
    local player, x = room:getPlayerById(effect.from), 0
    local deathcount = #(room.logic.event_recorder[GameEvent.Death] or {})
    while not player.dead and x < player.maxHp do
      x = x + 1
      local cards, canuse = room:getNCards(1), false
      local card = Fk:getCardById(cards[1])
      room:moveCardTo(cards, Card.Processing, nil, fk.ReasonJustMove, self.name, nil, true, player.id)
      if player.dead then
        room:cleanProcessingArea(cards, self.name)
      end
      local min_target = card.skill:getMinTargetNum()
      if min_target > 0 then
        local tos = table.simpleClone(room.alive_players)
        if card.trueName == "alliance_feast" then --联军的modTargetFilter会让司马懿自己通过判断从而要特殊处理
          table.removeOne(tos, player)
        end
        for _, p in pairs(tos) do
          if player:canUseTo(card, p, {bypass_times = true, extraUse = true, bypass_distances = true}) then
            canuse = true
            break
          end
        end
      elseif player:canUse(card, {bypass_times = true, extraUse = true, bypass_distances = true}) then
        canuse = true
      end
      if canuse then
        local use = U.askForUseRealCard(room, player, cards, nil, self.name,
        "#tyt_hc__zhouting-use:::"..card:toLogString(), {
          expand_pile = cards,
          bypass_times = true,
          extraUse = true,
          bypass_distances = true,
          tyt_hc__zhouting = player.id
        }, true, false)
        if use then
          use.extra_data = {
            bypass_times = true,
            bypass_distances = true,
            tyt_hc__zhouting = player.id}
          room:useCard(use)
        end
      else
        room:delay(800)
        room:obtainCard(player, card, true, fk.ReasonPrey)
      end
    end
    if player:getMark("tyt_hc__zhouting-reset-turn") > 0 then
      room:setPlayerMark(player, "tyt_hc__zhouting-reset-turn", 0)
      player:addSkillUseHistory(self.name, -1)
      room:sendLog{
        type = "#XiongsuanReset",
        from = player.id,
        arg = self.name,
      }
    end
  end,
}

local zhouting_refresh = fk.CreateTriggerSkill{
  name = "#tyt_hc__zhouting_refresh",
  refresh_events = {fk.Death},
  can_refresh = function(self, event, target, player, data)
    if data.damage and data.damage.card then
      local use = player.room.logic:getMostRecentEvent(GameEvent.UseCard).data[1]
      return (use.extra_data or {}).tyt_hc__zhouting == player.id
    end
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    room:setPlayerMark(player, "tyt_hc__zhouting-reset-turn", 1)
  end,
}

simayi:addSkill(quanbian)
yingshi:addRelatedSkill(yingshi_visible)
simayi:addSkill(yingshi)
zhouting:addRelatedSkill(zhouting_refresh)
simayi:addSkill(zhouting)

Fk:loadTranslationTable{
  ["tyt_hc_heg__n_simayif"] = "司马懿",
  ["#tyt_hc_heg__n_simayif"] = "通权达变",
  ["illustrator:tyt_hc_heg__n_simayif"] = "六道目",

  ["tyt_hc__quanbian"] = "权变",
  [":tyt_hc__quanbian"] = "当你于回合内使用或打出手牌时，你可以观看牌堆顶的X张牌并可以用一张牌交换其中的一张（X为你的体力上限）",
  ["tyt_hc__yingshi"] = "鹰眎",
  [":tyt_hc__yingshi"] = "锁定技，你的回合内，牌堆顶的X张牌对你可见（X为你的体力上限）。",
  ["tyt_hc__zhouting"] = "骤霆",
  [":tyt_hc__zhouting"] = "限定技，出牌阶段，你可以无距离次数限制依次使用牌堆顶的X张牌（X为你的体力上限），获得其中不能使用的牌，然后若你此次至少杀死过一名角色，你重置此技能。",

  ["#tyt_hc__quanbian-exchange"] = "权变：选择要交换的牌",
  ["#tyt_hc__quanbian-card"] = "你的牌",
  ["@[private]$tyt_hc__yingshi-turn"] = "鹰眎",
  ["#tyt_hc__yingshi"] = "鹰眎：牌堆顶的牌为 %arg",
  ["#tyt_hc__zhouting-use"] = "骤霆：使用 %arg",

  ["$tyt_hc__yingshi1"] = "鹰扬千里，明察秋毫。",
  ["$tyt_hc__yingshi2"] = "鸢飞戾天，目入百川。",
  ["$tyt_hc__zhouting1"] = "烈士雄心，志存高远。",
  ["$tyt_hc__zhouting2"] = "乱世之中，唯我司马！",
  ["$tyt_hc__quanbian1"] = "筹权谋变，步步为营。",
  ["$tyt_hc__quanbian2"] = "随机应变，谋国窃权。",
  ["~tyt_hc_heg__n_simayif"] = "虎入骷冢，司马难兴。",
}

local zhangchunhua = General(extension, "tyt_hc_heg__n_zhangchunhuaf", "jinz", 3, 3, General.Female)

local huishi = fk.CreateTriggerSkill{
  name = "tyt_hc__huishi",
  anim_type = "drawcard",
  events = {fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and player.phase == Player.Draw
      and table.find(player.room.alive_players, function (p)
      return H.getGeneralsRevealedNum(p) < 2
    end)
  end,
  on_cost = function(self, event, target, player, data)
    local n = 0
    table.forEach(player.room.alive_players, function (p) n = n + 2 - H.getGeneralsRevealedNum(p) end)
    n = math.min(n, #player.room.players)
    if player.room:askForSkillInvoke(player, self.name, nil, "#tyt_hc__huishi-invoke:::"..n) then
      self.cost_data = n
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local x = self.cost_data
    if x == 0 then return true end
    local card_ids = U.turnOverCardsFromDrawPile(player, x, self.name, false)
    local y = x // 2
    local rusult = room:askForGuanxing(player, card_ids, {x-y, x}, {y, y}, self.name, true, {"Bottom", "toObtain"})
    room:moveCardTo(rusult.bottom, Player.Hand, player, fk.ReasonPrey, self.name, "", false, player.id)
    U.returnCardsToDrawPile(player, rusult.top, self.name, false, false)
    return true
  end,
}

local qingleng = fk.CreateTriggerSkill{
  name = "tyt_hc__qingleng",
  anim_type = "offensive",
  events = {fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    return target ~= player and player:hasSkill(self) and target.phase == Player.Finish and
    H.getGeneralsRevealedNum(target) == 2 and not player:isNude() and not player:isProhibited(target, Fk:cloneCard("ice__slash"))
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local success, dat = room:askForUseActiveSkill(player, "#tyt_hc__qingleng_vs", "#tyt_hc__qingleng-invoke::"..target.id,  true, {bypass_distances = true, include_targets = {target.id}})
    if success and dat then
      self.cost_data = {dat.cards, dat.targets}
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local c = Fk:cloneCard("ice__slash")
    c.skillName = self.name
    c:addSubcards(self.cost_data[1])
    local use = { from = player.id, tos = { self.cost_data[2] }, card = c, extra_data = {bypass_distances = true, tyt_hc__qinglengfrom = player.id} }
    room:useCard(use)
  end,
}

local qingleng_vs = fk.CreateViewAsSkill {
  name = "#tyt_hc__qingleng_vs",
  handly_pile = true,
  min_card_num = 1,
  max_card_num = 1,
  card_filter = function(self, to_select, selected, player)
    if #selected == 0  then
      local slash = Fk:cloneCard("ice__slash")
      slash:addSubcard(to_select)
      return player:canUseTo(slash, Fk.currentRoom(player).current, {bypass_distances = true})
    end
  end,
  view_as = function(self, cards)
    if #cards ~= 1 then return end
    local c = Fk:cloneCard("ice__slash")
    c.skillName = qingleng.name
    c:addSubcards(cards)
    return c
  end,
}

local qingleng_delay = fk.CreateTriggerSkill{
  name = "#tyt_hc__qingleng_delay",
  anim_type = "offensive",
  events = {fk.CardUseFinished, fk.GeneralRevealed},
  can_trigger = function(self, event, target, player, data)
    if player.dead then return end
    if event == fk.CardUseFinished then
      if data.card.trueName == "slash" and not data.damageDealt and table.contains(data.card.skillNames, qingleng.name)
        and player.id == (data.extra_data or {}).tyt_hc__qinglengfrom then
        local to = player.room.current
        if H.getGeneralsRevealedNum(to) == 2 and not to.dead then
          self.cost_data = {tos = {to.id}}
          return not to.general:find("lord_") or not to.general:startsWith("blank_") or not to.deputyGeneral:startsWith("blank_")
        end
      end
    else
      for _, v in pairs(data) do
        for _, mark in ipairs(player:getTableMark("tyt_hc__qingleng")) do
          if mark[1] == target.id and mark[2] == v then
            self.cost_data = {tos = {target.id}}
            return not target.dead
          end
        end
      end
    end
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    local room = player.room
    player:broadcastSkillInvoke(qingleng.name)
    if event == fk.CardUseFinished then
      local to = player.room.current
      local isDeputy = H.doHideGeneral(room, player, to, qingleng.name)
      local name = H.getActualGeneral(to, isDeputy)
      room:addTableMarkIfNeed(player, "tyt_hc__qingleng", {to.id, name})
      room:addTableMark(to, "@tyt_hc__qingleng", name)
    else
      room:damage {
        from = player,
        to = target,
        damage = 1,
        skillName = qingleng.name,
      }
    end
  end,

  refresh_events = {fk.TurnStart},
  can_refresh = function (self, event, target, player, data)
    return player == target and #player:getTableMark("tyt_hc__qingleng") > 0
  end,
  on_refresh = function (self, event, target, player, data)
    local room = player.room
    for _, mark in ipairs(player:getTableMark("tyt_hc__qingleng")) do
      room:removeTableMark(room:getPlayerById(mark[1]), "@tyt_hc__qingleng", mark[2])
    end
    room:setPlayerMark(player, "tyt_hc__qingleng", 0)
  end,
}

zhangchunhua:addCompanions("tyt_hc_heg__n_simayif")
zhangchunhua:addSkill(huishi)
qingleng:addRelatedSkill(qingleng_vs)
qingleng:addRelatedSkill(qingleng_delay)
zhangchunhua:addSkill(qingleng)

Fk:loadTranslationTable{
  ["tyt_hc_heg__n_zhangchunhuaf"] = "张春华",
  ["#tyt_hc_heg__n_zhangchunhuaf"] = "宣穆皇后",
  ["illustrator:tyt_hc_heg__n_zhangchunhuaf"] = "六道目",

  ["tyt_hc__huishi"] = "慧识",
  [":tyt_hc__huishi"] = "摸牌阶段，你可以改为观看牌堆顶的X张牌（X为场上暗置武将牌数且至多为玩家数），获得其中一半的牌（向下取整），然后将其余牌置入牌堆底。",
  ["tyt_hc__qingleng"] = "清冷",
  [":tyt_hc__qingleng"] = "其他角色结束阶段，若其武将牌均明置，你可将一张牌当无距离限制的冰【杀】对其使用。"..
  "结算完成后，若此【杀】未造成过伤害，你暗置其一张武将牌，且直到你下回合开始，其明置此武将牌后，你对其造成1点伤害。",

  ["#tyt_hc__huishi-invoke"] = "慧识：你可以放弃摸牌，改为观看牌堆顶%arg张牌并获得其中的一半，其余置于牌堆底",
  ["#tyt_hc__qingleng-invoke"] = "清冷：你可以将一张牌当冰【杀】对 %dest 使用",
  ["@tyt_hc__qingleng"] = "清冷",
  ["#tyt_hc__qingleng_vs"] = "清冷",
  ["#tyt_hc__qingleng_delay"] = "清冷",

  ["$tyt_hc__huishi1"] = "你的想法，我已知晓。",
  ["$tyt_hc__huishi2"] = "妾身慧眼，已看透太多。",
  ["$tyt_hc__qingleng1"] = "冷冷清清，寂落沉沉。",
  ["$tyt_hc__qingleng2"] = "冷月葬情，深雪埋伤。",
  ["~tyt_hc_heg__n_zhangchunhuaf"] = "冷眸残情，孤苦为一人。",
}

local simashi = General(extension, "tyt_hc_heg__n_simashi", "jinz", 5)
simashi.mainMaxHpAdjustedValue = -2

local yimie = fk.CreateTriggerSkill{
  name = "tyt_hc__yimie",
  anim_type = "offensive",
  relate_to_place = "m",
  events = {fk.DamageCaused},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and data.to.hp > data.damage and
      player:usedSkillTimes(self.name, Player.HistoryTurn) == 0 and player.phase ~= Player.NotActive
  end,
  on_cost = function(self, event, target, player, data)
    if player.room:askForSkillInvoke(player, self.name, nil, "#tyt_hc__yimie-invoke::"..data.to.id) then
      self.cost_data = {tos = {data.to.id}}
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:loseHp(player, 1, self.name)
    local x = data.to.hp - data.damage
    if x > 0 then
      data.extra_data = data.extra_data or {}
      data.extra_data.tyt_hc__yimie = (data.extra_data.tyt_hc__yimie or 0) + x
      data.damage = data.to.hp
    end
  end,
}

local yimie_delay = fk.CreateTriggerSkill{
  name = "#tyt_hc__yimie_delay",
  events = {fk.DamageFinished},
  mute = true,
  can_trigger = function(self, event, target, player, data)
    return data.to == player and not player.dead and player:isWounded() and
    data.extra_data and data.extra_data.tyt_hc__yimie and data.dealtRecorderId
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    player.room:recover{
      who = player,
      num = data.extra_data.tyt_hc__yimie,
      skillName = yimie.name
    }
  end,
}

local tairan = fk.CreateTriggerSkill{
  name = "tyt_hc__tairan",
  anim_type = "special",
  events = {fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and player.phase == Player.Play
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local choices = {}
    for i = 1, player.hp, 1 do
      table.insert(choices, tostring(i))
    end
    table.insert(choices, "Cancel")
    local choice = room:askForChoice(player, choices, self.name, "#tyt_hc__tairan-hp")
    if choice ~= "Cancel" then
      room:loseHp(player, tonumber(choice), self.name)
      room:addPlayerMark(player, "@tyt_hc__tairan-hp-turn", tonumber(choice))
    end
    if player:isWounded() and not player:isNude() then
      local cards = room:askForDiscard(player, 1, player:getLostHp(), true, self.name, true, ".", "#tyt_hc__tairan-cards")
      if #cards > 0 then
        room:addPlayerMark(player, "@tyt_hc__tairan-cards-turn", #cards)
      end
    end
  end,
}

local tairan_delay = fk.CreateTriggerSkill{
  name = "#tyt_hc__taira_delay",
  events = {fk.EventPhaseStart},
  anim_type = "defensive",
  frequency = Skill.Compulsory,
  can_trigger = function(self, event, target, player, data)
    return target == player and not player.dead and player.phase == Player.Finish and
    (player:getMark("@tyt_hc__tairan-cards-turn") > 0 or (player:getMark("@tyt_hc__tairan-hp-turn") > 0 and player:isWounded()))
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    player:broadcastSkillInvoke(tairan.name)
    if player:getMark("@tyt_hc__tairan-cards-turn") > 0 then
      player:drawCards(player:getMark("@tyt_hc__tairan-cards-turn"), tairan.name)
    end
    if player:getMark("@tyt_hc__tairan-hp-turn") > 0 and player:isWounded() and not player.dead then
      player.room:recover{
      who = player,
      num = math.min(player:getMark("@tyt_hc__tairan-hp-turn"), player:getLostHp()),
      skillName = tairan.name
    }
    end
  end,
}

yimie:addRelatedSkill(yimie_delay)
tairan:addRelatedSkill(tairan_delay)
simashi:addSkill(yimie)
simashi:addSkill(tairan)


Fk:loadTranslationTable{
  ["tyt_hc_heg__n_simashi"] = "司马师",
  ["#tyt_hc_heg__n_simashi"] = "晋景王",
  ["illustrator:tyt_hc_heg__n_simashi"] = "拉布拉卡",

  ["tyt_hc__yimie"] = "夷灭",
  [":tyt_hc__yimie"] = "主将技，此武将牌减少一个阴阳鱼；你的回合限一次，当你对一名其他角色造成伤害时，你可失去1点体力，令此伤害值+X（X为其体力值减去伤害值）。伤害结算后，其回复等量体力。",
  ["tyt_hc__tairan"] = "泰然",
  [":tyt_hc__tairan"] = "出牌阶段开始时，你可以失去任意点体力，弃置至多X张牌（X为你已损失体力值），若如此做，结束阶段，你摸等量张牌，回复等量体力。",

  ["#tyt_hc__yimie_delay"] = "夷灭",
  ["#tyt_hc__taira_delay"] = "泰然",
  ["#tyt_hc__yimie-invoke"] = "夷灭：你可以失去1点体力，令你对 %dest 造成的伤害增加其体力值",
  ["#tyt_hc__tairan-hp"] = "泰然：选择要失去的体力值",
  ["#tyt_hc__tairan-cards"] = "泰然：你可弃置至多已损失体力张张牌",
  ["@tyt_hc__tairan-hp-turn"] = "泰然 体力",
  ["@tyt_hc__tairan-cards-turn"] = "泰然 牌数",

  ["$tyt_hc__yimie1"] = "汝大逆不道，当死无赦！",
  ["$tyt_hc__yimie2"] = "斩草除根，灭其退路！",
  ["$tyt_hc__tairan1"] = "撼山易，撼我司马氏难。",
  ["$tyt_hc__tairan2"] = "云卷云舒，处之泰然。",
  ["~tyt_hc_heg__n_simashi"] = "子上，这是为兄给你打下的江山……",
}

local simazhao = General(extension, "tyt_hc_heg__n_simazhaof", "jinz", 3)

local choufa = fk.CreateActiveSkill{
  name = "tyt_hc__choufa",
  anim_type = "control",
  card_num = 0,
  target_num = 1,
  prompt = "#tyt_hc__choufa",
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) == 0
  end,
  card_filter = Util.FalseFunc,
  target_filter = function(self, to_select, selected, selected_cards, card, extra_data, player)
    return #selected == 0 and to_select ~= player.id and not Fk:currentRoom():getPlayerById(to_select):isKongcheng()
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local target = room:getPlayerById(effect.tos[1])
    local card = room:askForCardChosen(player, target, "h", self.name)
    target:showCards(card)
    if not target.dead then
      local card_types = {Card.TypeBasic, Card.TypeTrick, Card.TypeEquip}
      table.removeOne(card_types, Fk:getCardById(card).type)
      local mark = target:getTableMark("@[cardtypes]tyt_hc__choufa-turn")
      table.insertTableIfNeed(mark, card_types)
      room:setPlayerMark(target, "@[cardtypes]tyt_hc__choufa-turn", mark)
      target:filterHandcards()
    end
  end,
}

local choufa_filter = fk.CreateFilterSkill{
  name = "#tyt_hc__choufa_filter",
  card_filter = function(self, card, player)
    return table.contains(player:getTableMark("@[cardtypes]tyt_hc__choufa-turn"), card.type)
  end,
  view_as = function(self, card)
    return Fk:cloneCard("slash", card.suit, card.number)
  end,
}

local zhaoran = fk.CreateTriggerSkill{
  name = "tyt_hc__zhaoran",
  anim_type = "drawcard",
  events = {fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and player.phase == Player.Play
  end,
  on_cost = function(self, event, target, player, data)
    return player.room:askForSkillInvoke(player, self.name, nil, "#tyt_hc__zhaoran-invoke")
  end,
  on_use = function(self, event, target, player, data)
    player.room:setPlayerMark(player, "@tyt_hc__zhaoran-phase", {})
    player:showCards(player:getCardIds("h"))
  end,
}

local zhaoran_trigger = fk.CreateTriggerSkill{
  name = "#tyt_hc__zhaoran_trigger",
  anim_type = "drawcard",
  events = {fk.AfterCardsMove},
  can_trigger = function(self, event, target, player, data)
    if player:usedSkillTimes("tyt_hc__zhaoran", Player.HistoryPhase) > 0 then
      for _, move in ipairs(data) do
        if move.from == player.id then
          for _, info in ipairs(move.moveInfo) do
            if info.fromArea == Card.PlayerHand then
              if not table.find(player:getCardIds("h"), function(id)
                return Fk:getCardById(id).suit == Fk:getCardById(info.cardId).suit end) and
                not table.contains(player:getMark("@tyt_hc__zhaoran-phase"), Fk:getCardById(info.cardId):getSuitString(true)) then
                return true
              end
            end
          end
        end
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local suits = {}
    for _, move in ipairs(data) do
      if move.from == player.id then
        for _, info in ipairs(move.moveInfo) do
          if info.fromArea == Card.PlayerHand then
            if not table.find(player:getCardIds("h"), function(id)
              return Fk:getCardById(id).suit == Fk:getCardById(info.cardId).suit end) and
              not table.contains(player:getMark("@tyt_hc__zhaoran-phase"), Fk:getCardById(info.cardId):getSuitString(true)) then
              table.insertIfNeed(suits, Fk:getCardById(info.cardId):getSuitString(true))
            end
          end
        end
      end
    end
    local mark = player:getMark("@tyt_hc__zhaoran-phase")
    table.insertTableIfNeed(mark, suits)
    player.room:setPlayerMark(player, "@tyt_hc__zhaoran-phase", mark)
    for i = 1, #suits, 1 do
      player:broadcastSkillInvoke("tyt_hc__zhaoran")
      if table.every(room:getOtherPlayers(player, false), function(p) return p:isNude() end) then
        player:drawCards(1, "zhaoran")
      else
        local targets = table.map(table.filter(room:getOtherPlayers(player, false), function (p)
          return not p:isNude() end), Util.IdMapper)
        local to = room:askForChoosePlayers(player, targets, 1, 1, "#tyt_hc__zhaoran-discard", "tyt_hc__zhaoran", true)
        if #to > 0 then
          local id = room:askForCardChosen(player, room:getPlayerById(to[1]), "he", "tyt_hc__zhaoran")
          room:throwCard({id}, "tyt_hc__zhaoran", room:getPlayerById(to[1]), player)
        else
          player:drawCards(1, "tyt_hc__zhaoran")
        end
      end
    end
  end,
}

local zhaoran_visible = fk.CreateVisibilitySkill{
  name = "#tyt_hc__zhaoran_visible",
  frequency = Skill.Compulsory,
  card_visible = function(self, player, card)
    if card and Fk:currentRoom():getCardOwner(card) and Fk:currentRoom():getCardOwner(card):usedSkillTimes("tyt_hc__zhaoran", Player.HistoryPhase) > 0 and
      Fk:currentRoom():getCardArea(card) == Card.PlayerHand then
      return true
    end
  end
}

choufa:addRelatedSkill(choufa_filter)
zhaoran:addRelatedSkill(zhaoran_trigger)
zhaoran:addRelatedSkill(zhaoran_visible)
simazhao:addSkill(zhaoran)
simazhao:addSkill(choufa)

Fk:loadTranslationTable{
  ["tyt_hc_heg__n_simazhaof"] = "司马昭",
  ["#tyt_hc_heg__n_simazhaof"] = "晋文帝",
  ["illustrator:tyt_hc_heg__n_simazhaof"] = "君桓文化",

  ["tyt_hc__choufa"] = "筹伐",
  [":tyt_hc__choufa"] = "出牌阶段限一次，你可展示一名其他角色的一张手牌，本回合其与之类别不同的手牌均视为【杀】。",
  ["tyt_hc__zhaoran"] = "昭然",
  [":tyt_hc__zhaoran"] = "出牌阶段开始时，你可以展示所有手牌直到此阶段结束，若如此做，当你于本阶段失去任意花色的最后一张手牌时（每种花色限一次），"..
  "你可以摸一张牌或弃置一名其他角色的一张牌。",

  ["#tyt_hc__choufa"] = "筹伐：展示一名其他角色一张手牌，本回合其与之类别不同的手牌均视为【杀】",
  ["@[cardtypes]tyt_hc__choufa-turn"] = "筹伐",
  ["#tyt_hc__choufa_filter"] = "筹伐",
  ["#tyt_hc__zhaoran-invoke"] = "昭然：你可以展示所有手牌，本阶段你失去一种花色最后的手牌后摸一张牌或弃置一名角色一张牌",
  ["@tyt_hc__zhaoran-phase"] = "昭然",
  ["#tyt_hc__zhaoran_trigger"] = "昭然",
  ["#tyt_hc__zhaoran-discard"] = "昭然：弃置一名其他角色一张牌，或点“取消”摸一张牌",

  ["$tyt_hc__choufa1"] = "秣马厉兵，筹伐不臣！",
  ["$tyt_hc__choufa2"] = "枕戈待旦，秣马征平。",
  ["$tyt_hc__zhaoran1"] = "行昭然于世，赦众贼以威。",
  ["$tyt_hc__zhaoran2"] = "吾之心思，路人皆知。",
  ["~tyt_hc_heg__n_simazhaof"] = "司马三代，一梦成空……",
}

local simazhou = General(extension, "tyt_hc_heg__n_simazhou", "jinz", 4)

local caiwang = fk.CreateTriggerSkill{
  name = "tyt_hc__caiwang",
  mute = true,
  events = {fk.AfterCardsMove},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self) then
      local cards = {}
      for _, move in ipairs(data) do
        if move.skillName and move.skillName:startsWith("alliance") and move.skillName:endsWith("&")then
          if move.to == player.id and move.toArea == Card.PlayerHand and move.from ~= nil or move.from == player.id then
            for _, info in ipairs(move.moveInfo) do
              table.insertIfNeed(cards, info.cardId)
            end
          end
        end
      end
      if #cards > 0 then
        self.cost_data = {}
        self.cost_data.method = "discard"
        self.cost_data.tos = {}
        local color = Fk:getCardById(cards[1]).color
        for _, cardid in ipairs(cards) do
          if color ~= Fk:getCardById(cardid).color then
            self.cost_data.method = "draw"
            break
          end
        end
        return self.cost_data.method == "draw" or table.find(player.room:getOtherPlayers(player, false), function (p)
          return not p:isNude() end)
      end
    end
  end,
  on_cost = function(self, event, target, player, data)
    if self.cost_data.method == "draw" then
      return true
    else
      local room = player.room
      local targets = table.map(table.filter(room:getOtherPlayers(player, false), function (p)
        return not p:isNude() end), Util.IdMapper)
      local to = room:askForChoosePlayers(player, targets, 1, 1, "#tyt_hc__caiwang-discard", self.name, true)
      if #to > 0 then
        self.cost_data.tos = to
        return true
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    player:broadcastSkillInvoke(self.name)
    if self.cost_data.method == "draw" then
      room:notifySkillInvoked(player, self.name, "drawcard")
      player:drawCards(1, self.name)
    else
      room:notifySkillInvoked(player, self.name, "control")
      local targets = room:getPlayerById(self.cost_data.tos[1])
      local id = room:askForCardChosen(player, targets, "he", self.name)
      room:throwCard({id}, self.name, targets, player)
    end
  end,
}

local caiwang_alliance = H.CreateAllianceSkill{
  name = "#tyt_hc__caiwang_alliance",
  allow_alliance = function(self, from, to)
    return from:hasShownSkill(caiwang) and from ~= to
  end
}

local naxiang = fk.CreateTriggerSkill{
  name = "tyt_hc__naxiang",
  anim_type = "special",
  frequency = Skill.Compulsory,
  events = {fk.Damage, fk.Damaged},
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(self) then
      local to = event == fk.Damage and data.to or data.from
      self.cost_data = {tos = {to.id}}
      return H.compareKingdomWith(player, to, true) and not to.dead
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local to = event == fk.Damage and data.to or data.from
    if not H.askCommandTo(player, to, self.name) then
      room:invalidateSkill(player, self.name)
      room:setPlayerMark(player, "@@tyt_hc__naxiang", 1)
      for _, cid in ipairs(player:getCardIds(Player.Hand)) do
        local c = Fk:getCardById(cid)
        if c:getMark("@@alliance") == 0 then
          room:setCardMark(c, "@@alliance-naxiang-inhand", 1)
        end
      end
    end
  end,

  refresh_events = {fk.TurnStart, fk.AfterCardsMove},
  can_refresh = function(self, event, target, player, data)
    if player:getMark("@@tyt_hc__naxiang") == 0 then return end
    if event == fk.TurnStart then return target == player end
    for _, move in ipairs(data) do
      if move.to == player.id and move.toArea == Card.PlayerHand then
        return true
      end
    end
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    if event == fk.TurnStart then
      room:validateSkill(player, self.name)
      room:setPlayerMark(player, "@@tyt_hc__naxiang", 0)
      U.clearHandMark(player, "@@alliance-naxiang-inhand")
    else
      for _, cid in ipairs(player:getCardIds(Player.Hand)) do
        local c = Fk:getCardById(cid)
        if c:getMark("@@alliance") == 0 then
          room:setCardMark(c, "@@alliance-naxiang-inhand", 1)
        end
      end
    end
  end,
}

local naxiang_alliance = H.CreateAllianceSkill{
  name = "#tyt_hc__naxiang_alliance",
  allow_alliance = function(self, from, to)
    return to:getMark("@@tyt_hc__naxiang") > 0 and from ~= to
  end
}

caiwang:addRelatedSkill(caiwang_alliance)
naxiang:addRelatedSkill(naxiang_alliance)
simazhou:addSkill(caiwang)
simazhou:addSkill(naxiang)

Fk:loadTranslationTable{
  ["tyt_hc_heg__n_simazhou"] = "司马伷",
  ["#tyt_hc_heg__n_simazhou"] = "琅琊武王",
  ["illustrator:tyt_hc_heg__n_simazhou"] = "凝聚永恒",

  ["tyt_hc__caiwang"] = "才望",
  [":tyt_hc__caiwang"] = "其他角色是你合纵的合法目标；当你因发动合纵而失去牌/成为合纵目标而获得牌后，"..
    "若这些牌颜色：均相同，你可以弃置一名其他角色的一张牌；不均相同，你摸一张牌。",
  ["tyt_hc__naxiang"] = "纳降",
  [":tyt_hc__naxiang"] = "锁定技，当与你势力不同的角色对你造成伤害或受到你的伤害后，你对其发起军令，若其不执行，直到你下回合开始，"..
    "此技能失效，你是其他角色合纵的合法目标，你的手牌均视为带有“合纵”。",

  ["#tyt_hc__caiwang-discard"] = "才望：你可以弃置其他角色一张牌",
  ["@@tyt_hc__naxiang"] = "纳降",
  ["@@alliance-naxiang-inhand"] = "合",

  ["$tyt_hc__caiwang1"] = "才气不俗，声望四海。",
  ["$tyt_hc__caiwang2"] = "绥怀之称，监守邺城。",
  ["$tyt_hc__naxiang1"] = "奉命伐吴，得胜纳降。",
  ["$tyt_hc__naxiang2"] = "进军逼江，震慑吴贼。",
  ["~tyt_hc_heg__n_simazhou"] = "恩赐重物，病身难消受……",
}

local zhanghuyuechen = General(extension, "tyt_hc_heg__n_zhanghuyuechen", "jinz", 4)

local xijue = fk.CreateTriggerSkill{
  name = "tyt_hc__xijue",
  mute = true,
  events = {fk.GeneralRevealed, fk.TurnEnd, fk.DrawNCards},
  can_trigger = function(self, event, target, player, data)
    if not player:hasSkill(self) then return end
    if event == fk.GeneralRevealed then
      if target ~= player or player:getMark("tyt_hc__xijue_show") > 0 then return false end
      for _, v in pairs(data) do
        if table.contains(Fk.generals[v]:getSkillNameList(), self.name) then return true end
      end
    elseif event == fk.TurnEnd then
      return target == player and #player.room.logic:getActualDamageEvents(1, function(e) return e.data[1].from == player end) > 0
    else
      return target == player and player:getMark("@tyt_hc__jue") > 0
    end
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    local room = player.room
    player:broadcastSkillInvoke(self.name, math.random(1, 2))
    if event == fk.GeneralRevealed then
      room:notifySkillInvoked(player, self.name)
      room:setPlayerMark(player, "tyt_hc__xijue_show", 1)
      room:addPlayerMark(player, "@tyt_hc__jue", 2)
    elseif event == fk.TurnEnd then
      room:notifySkillInvoked(player, self.name)
      room:addPlayerMark(player, "@tyt_hc__jue", 1)
    else
      local n = math.min(player:getMark("@tyt_hc__jue"), player.maxHp)
      room:notifySkillInvoked(player, self.name, n >= data.n and "drawcard" or "negative")
      data.n = n
    end
  end,

  on_lose = function (self, player, is_death)
    player.room:setPlayerMark(player, "@tyt_hc__jue", 0)
  end,
}

local xijue_tuxi = fk.CreateTriggerSkill{
  name = "#tyt_hc__xijue_tuxi",
  anim_type = "control",
  main_skill = xijue,
  events = {fk.DrawNCards},
  can_trigger = function(self, event, target, player, data)
    return (target == player and player:hasSkill(xijue) and data.n > 0 and
      not table.every(player.room:getOtherPlayers(player, false), function (p) return p:isKongcheng() end))
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local targets = table.map(table.filter(room:getOtherPlayers(player, false), function(p)
      return not p:isKongcheng() end), Util.IdMapper)
    local tos = room:askForChoosePlayers(player, targets, 1, data.n, "#tyt_hc__xijue_tuxi-invoke:::"..data.n, self.name, true)
    if #tos > 0 then
      self.cost_data = {tos = tos}
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    player:broadcastSkillInvoke(xijue.name, math.random(3, 4))
    local targets = table.simpleClone(self.cost_data.tos)
    room:sortPlayersByAction(targets)
    for _, id in ipairs(targets) do
      if player.dead then break end
      local p = room:getPlayerById(id)
      if not (p.dead or p:isKongcheng()) then
        local c = room:askForCardChosen(player, p, "h", self.name)
        room:obtainCard(player.id, c, false, fk.ReasonPrey)
      end
    end
    data.n = data.n - #targets
    room:removePlayerMark(player, "@tyt_hc__jue")
  end,
}

local xijue_xiaoguo = fk.CreateTriggerSkill{
  name = "#tyt_hc__xijue_xiaoguo",
  anim_type = "offensive",
  events = {fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    return target ~= player and player:hasSkill(xijue) and target.phase == Player.Start and not player:isKongcheng() and not target.dead and player:getMark("@tyt_hc__jue") > 0
  end,
  on_cost = function(self, event, target, player, data)
    local n = math.min(player:getMark("@tyt_hc__jue"), player.maxHp)
    local card = player.room:askForDiscard(player, 1, n, true, self.name, true,
      ".|.|.|.|.|basic", "#tyt_hc__xijue_xiaoguo-invoke::"..target.id..":"..n, true)
    if #card > 0 then
      self.cost_data = {cards = card, tos = {target.id}}
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    player:broadcastSkillInvoke(xijue.name, math.random(5, 6))
    room:throwCard(self.cost_data.cards, self.name, player, player)
    local x, y = #self.cost_data.cards, 0
    if #target:getCardIds(Player.Equip) > 0 then
      local equips = room:askForCardsChosen(player, target, math.min(x, #target:getCardIds(Player.Equip)), math.min(x, #target:getCardIds(Player.Equip)), "e", self.name)
      if #equips > 0 then
        local count = #(room.logic.event_recorder[GameEvent.MoveCards] or Util.DummyTable)
        room:throwCard(equips, self.name, target, player)
        local e = HC.GetRecentMoveEventByskill(room, self.name, count)
        if e then
          for _, move in ipairs(e.data) do
            for _, info in ipairs(move.moveInfo) do
              if Fk:getCardById(info.cardId).type == Card.TypeEquip then
                y = y + 1
              elseif Fk:getCardById(info.cardId).type == Card.TypeBasic then
                x = x + 1
              end
            end
          end
        end
      end
    end
    if x > y then
      if not player.dead then
        player:drawCards(1, self.name)
      end
      if not target.dead then
        room:damage{
        from = player,
        to = target,
        damage = 1,
        skillName = self.name,
      }
      end
    end
    room:removePlayerMark(player, "@tyt_hc__jue")
  end,
}

xijue:addRelatedSkill(xijue_tuxi)
xijue:addRelatedSkill(xijue_xiaoguo)
zhanghuyuechen:addSkill(xijue)

Fk:loadTranslationTable{
  ["tyt_hc_heg__n_zhanghuyuechen"] = "张虎乐綝",
  ["#tyt_hc_heg__n_zhanghuyuechen"] = "不辱门庭",
  ["illustrator:tyt_hc_heg__n_zhanghuyuechen"] = "凝聚永恒",

  ["tyt_hc__xijue"] = "袭爵",
  [":tyt_hc__xijue"] = "当你首次明置此武将牌后，你获得2枚“爵”；回合结束时，若你本回合造成过伤害，你获得1枚“爵”；摸牌阶段，你改为摸X张牌；"..
    "摸牌阶段，你可以发动〖突袭〗并移去1枚“爵”；其他角色的准备阶段，你可以发动〖骁果〗（至多弃置X张基本牌）并移去1枚“爵”。（X为“爵”数且至多为你的体力上限）",
  
  ["@tyt_hc__jue"] = "爵",
  ["#tyt_hc__xijue_tuxi-invoke"] = "袭爵：你可以发动〖突袭〗，少摸至多%arg张牌，获得等量其他角色各一张手牌",
  ["#tyt_hc__xijue_tuxi"] = "突袭",
  [":tyt_hc__xijue_tuxi"] = "摸牌阶段，你可以少摸任意张牌并获得等量其他角色各一张手牌。",
  ["#tyt_hc__xijue_xiaoguo"] = "骁果",
  [":tyt_hc__xijue_xiaoguo"] = "其他角色的准备阶段，你可以弃置至少一张至多X张基本牌（X为“爵”数且至多为你的体力上限），然后弃置其装备区等量张牌，若你弃置的装备牌数小于基本牌数，你摸一张牌并对其造成1点伤害。",
  ["#tyt_hc__xijue_xiaoguo-invoke"] = "袭爵：你可弃置至多%arg张基本牌，对 %dest 发动〖骁果〗",

  ["$tyt_hc__xijue1"] = "承爵于父，安能辱之！",
  ["$tyt_hc__xijue2"] = "虎父安有犬子乎？",
  ["$tyt_hc__xijue3"] = "动如霹雳，威震宵小！",
  ["$tyt_hc__xijue4"] = "行略如风，摧枯拉朽！",
  ["$tyt_hc__xijue5"] = "大丈夫生于世，当沙场效忠！",
  ["$tyt_hc__xijue6"] = "骁勇善战，刚毅果断！",
  ["~tyt_hc_heg__n_zhanghuyuechen"] = "儿有辱……父亲威名……",
}

local xiahouhui = General(extension, "tyt_hc_heg__n_xiahouhui", "jinz", 3, 3, General.Female)

local yishi = fk.CreateTriggerSkill{
  name = "tyt_hc__yishi",
  anim_type = "support",
  events = {fk.AfterCardsMove},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self) and player:usedSkillTimes(self.name, Player.HistoryTurn) == 0 then
      local room = player.room
      local tos, cards = {}, {}
      for _, move in ipairs(data) do
        if move.from and move.from ~= player.id and move.moveReason == fk.ReasonDiscard
        and room:getPlayerById(move.from).phase == Player.Play and not room:getPlayerById(move.from).dead then
          tos = {move.from}
          for _, info in ipairs(move.moveInfo) do
            if info.fromArea == Card.PlayerHand and room:getCardArea(info.cardId) == Card.DiscardPile then
              table.insertIfNeed(cards, info.cardId)
            end
          end
        end
      end
      cards = U.moveCardsHoldingAreaCheck(room, cards)
      if #cards> 0 then
        self.cost_data = {cards = cards, tos = tos}
        return true
      end
    end
  end,
  on_cost = function(self, event, target, player, data)
    local to = player.room:getPlayerById(self.cost_data.tos[1])
    local cards = self.cost_data.cards
    local tocards = player.room:askForCard(player, 1, 1, false, self.name, true, ".|.|.|.|.|.|"..table.concat(cards, ","), "#tyt_hc__yishi-card:"..to.id, cards)
    if #tocards > 0 then
      self.cost_data.cards = tocards
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local to = room:getPlayerById(self.cost_data.tos[1])
    local cards = self.cost_data.cards
    room:moveCardTo(cards, Player.Hand, to, fk.ReasonPrey, self.name)
    if player.dead then return end
    cards = U.moveCardsHoldingAreaCheck(room, cards)
    if #cards > 0 then
      room:moveCardTo(cards, Player.Hand, player, fk.ReasonPrey, self.name)
    end
  end,
}

local shidu = fk.CreateActiveSkill{
  name = "tyt_hc__shidu",
  anim_type = "control",
  prompt = "#tyt_hc__shidu-active",
  card_num = 0,
  target_num = 1,
  can_use = function(self, player)
    return not player:isKongcheng() and player:usedSkillTimes(self.name, Player.HistoryPhase) == 0
  end,
  card_filter = Util.FalseFunc,
  target_filter = function(self, to_select, selected, selected_cards, card, extra_data, player)
    return #selected == 0 and to_select ~= player.id and player:canPindian(Fk:currentRoom():getPlayerById(to_select))
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local target = room:getPlayerById(effect.tos[1])
    local pindian = player:pindian({target}, self.name)
    if pindian.results[target.id].winner == player and not (player.dead or target.dead) then
      local cards = target:getCardIds(Player.Hand)
      if #cards > 0 then
        room:obtainCard(player, cards, false, fk.ReasonPrey)
        if player.dead or target.dead then return end
      end
      local n = #player:getCardIds(Player.Hand)
      if n > 1 then
        cards = room:askForCard(player, (n//2), (n//2), false, self.name, false, ".",
        "#tyt_hc__shidu-give::".. target.id .. ":"..tostring(n//2))
        room:obtainCard(target, cards, false, fk.ReasonGive)
      end
    end
  end,
}

local baoqie = fk.CreateTriggerSkill{
  name = "tyt_hc__baoqie",
  mute = true,
  events = {fk.DamageInflicted, fk.GeneralRevealed},
  can_trigger = function (self, event, target, player, data)
    if target ~= player or not player:hasSkill(self) or player:getMark(self.name) > 0 then return false end
    if event == fk.GeneralRevealed then
      for _, v in pairs(data) do
        if table.contains(Fk.generals[v]:getSkillNameList(), self.name) then return true end
      end
    else
      return player.phase == Player.NotActive and not player:hasShownSkill(self)
        and (table.contains(Fk.generals[H.getActualGeneral(player, false)]:getSkillNameList(), self.name)
        or table.contains(Fk.generals[H.getActualGeneral(player, true)]:getSkillNameList(), self.name))
    end
  end,
  on_cost =function (self, event, target, player, data)
    if event == fk.GeneralRevealed then
      return true
    else
      return player.room:askForSkillInvoke(player, self.name)
    end
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    if event == fk.DamageInflicted then
      room:notifySkillInvoked(player, self.name, "defensive")
      player:broadcastSkillInvoke(self.name)
      return true
    else
      room:addPlayerMark(player, self.name)

      local targets = table.map(table.filter(room.alive_players, function (p)
        return p:getEquipment(Card.SubtypeTreasure) ~= nil
      end), Util.IdMapper)
      if #targets > 0 then
        local victims = room:askForChoosePlayers(player, targets, 1, 1, "#tyt_hc__baoqie", self.name)
        if #victims > 0 then
          room:notifySkillInvoked(player, self.name, "offensive", victims)
          player:broadcastSkillInvoke(self.name)
          local cards = room:getPlayerById(victims[1]):getEquipment(Card.SubtypeTreasure)
          if cards == nil then return end
          local first = #(room.logic.event_recorder[GameEvent.MoveCards] or Util.DummyTable)
          room:obtainCard(player, cards, true, fk.ReasonPrey, player.id, self.name)
          local e = HC.GetRecentMoveEventByskill(room, self.name, first)
          if e == nil then return end
          local tcards = {}
          for _, move in ipairs(e.data) do
            for _, info in ipairs(move.moveInfo) do
              table.insertIfNeed(tcards, info.cardId)
            end
          end
          tcards = U.moveCardsHoldingAreaCheck(room, tcards, e.id)
          if #tcards > 0 then
            U.askForUseRealCard(room, player, tcards, nil, self.name,
            "#tyt_hc__baoqie-use", {
              bypass_times = true,
              extraUse = true,
            })
          end
          return
        end
      end
    end
  end,
}

xiahouhui:addCompanions("tyt_hc_heg__n_simashi")
xiahouhui:addSkill(yishi)
xiahouhui:addSkill(shidu)
xiahouhui:addSkill(baoqie)

Fk:loadTranslationTable{
  ["tyt_hc_heg__n_xiahouhui"] = "夏侯徽",
  ["#tyt_hc_heg__n_xiahouhui"] = "景怀皇后",
  ["illustrator:tyt_hc_heg__n_xiahouhui"] = "六道目",

  ["tyt_hc__baoqie"] = "宝箧",
  [":tyt_hc__baoqie"] = "当你于回合外受到伤害时，若你未明置过此武将牌，你可以明置此武将牌并防止此伤害；当你首次明置此武将牌后，你可以获得场上的一张宝物牌，然后你可以使用之。",
  ["tyt_hc__yishi"] = "宜室",
  [":tyt_hc__yishi"] = "每回合限一次，当一名其他角色于其出牌阶段弃置手牌后，你可以令其获得其中的一张牌，然后你获得其余的牌。",
  ["tyt_hc__shidu"] = "识度",
  [":tyt_hc__shidu"] = "出牌阶段限一次，你可以与一名角色拼点，若你赢，你获得其所有手牌，然后你交给其你的一半手牌（向下取整）。",

  ["#tyt_hc__shidu-active"] = "发动 识度，与一名角色拼点，若你赢，你获得其所有手牌并交给其一半的手牌",
  ["#tyt_hc__yishi-invoke"] = "宜室：你可以令 %dest 收回一张弃置的牌，你获得其余的牌",
  ["#tyt_hc__yishi-card"] = "是否发动〖宜室〗，选择一张牌还给 %src",
  ["#tyt_hc__shidu-give"] = "识度：选择 %arg 张手牌交还给 %dest",
  ["#tyt_hc__baoqie"] = "是否发动〖宝箧〗，选择一名角色，获得其装备区的宝物牌",
  ["#tyt_hc__baoqie-use"] = "宝箧：你可以使用此牌",

  ["$tyt_hc__baoqie1"] = "宝箧藏玺，时局变动。",
  ["$tyt_hc__baoqie2"] = "曹亡宝箧，尽露锋芒。",
  ["$tyt_hc__yishi1"] = "家庭和顺，夫妻和睦。",
  ["$tyt_hc__yishi2"] = "之子于归，宜其室家。",
  ["$tyt_hc__shidu1"] = "鉴识得体，气度雅涵。",
  ["$tyt_hc__shidu2"] = "宽容体谅，宽人益己。",
  ["~tyt_hc_heg__n_xiahouhui"] = "夫君，你怎么对我如此狠心……",
}

local shibao = General(extension, "tyt_hc_heg__n_shibao", "jinz", 4)

local function hasMark(object, markname, suffixes)
  if not object then return false end
  for mark, _ in pairs(object.mark) do
    if mark == markname then return true end
    if mark:startsWith(markname .. "-") then
      for _, suffix in ipairs(suffixes) do
        if mark:find(suffix, 1, true) then return true end
      end
    end
  end
  return false
end

local zhuosheng = fk.CreateViewAsSkill{
  name = "tyt_hc__zhuosheng",
  pattern = ".|.|.|.|.|basic",
  handly_pile = true,
  interaction = function(self, player)
    local all_names = U.getAllCardNames("b")
    local ban_names = player:getTableMark("tyt_hc__zhuosheng-turn")
    local names = U.getViewAsCardNames(player, self.name, all_names, {}, ban_names)
    if #names == 0 then return false end
    return UI.ComboBox { choices = names, all_choices = all_names }
  end,
  card_filter = function(self, to_select, selected, player)
    return table.contains(player:getHandlyIds(), to_select)
  end,
  view_as = function(self, cards)
    if #cards < 2 or not self.interaction.data then return end
    local card = Fk:cloneCard(self.interaction.data)
    card:addSubcards(cards)
    card.skillName = self.name
    return card
  end,
  before_use = function (self, player, use)
    player.room:addTableMark(player, "tyt_hc__zhuosheng-turn", use.card.trueName)
  end,
  after_use = function(self, player, use)
    if not player.dead then
    local n = 0
    for _, cid in ipairs(use.card.subcards) do
      local c = Fk:getCardById(cid)
      if hasMark(c, "@@alliance", MarkEnum.CardTempMarkSuffix) then
        n = n + 1
        break
      end
    end
    if n > 0 then
      player:drawCards(n, self.name)
    end
    end
  end,
  enabled_at_play = function(self, player)
    local all_names = U.getAllCardNames("b")
    local ban_names = player:getTableMark("tyt_hc__zhuosheng-turn")
    local names = U.getViewAsCardNames(player, self.name, all_names, {}, ban_names)
    return #names > 0
  end,
  enabled_at_response = function(self, player, response)
    if response then return false end
    local all_names = U.getAllCardNames("b")
    local ban_names = player:getTableMark("tyt_hc__zhuosheng-turn")
    local names = U.getViewAsCardNames(player, self.name, all_names, {}, ban_names)
    return #names > 0 and Fk:currentRoom():getCurrent()
  end,
}

local juhou = H.CreateArraySummonSkill{
  name = "tyt_hc__juhou",
  array_type = "formation",
}

local juhou_trigger = fk.CreateTriggerSkill{
  name = "#tyt_hc__juhou_trigger",
  anim_type = "defensive",
  main_skill = juhou,
  events = {fk.TargetConfirmed},
  can_trigger = function(self, event, target, player, data)
    if not player:hasSkill(juhou) or #player.room.alive_players < 4 then return end
    return H.inFormationRelation(player, target) and not target:isKongcheng() and (data.card.trueName == "slash" or data.card:isCommonTrick())
      and (player == target or player:hasShownSkill(self))
  end,
  on_cost = function(self, event, target, player, data)
    local cards = player.room:askForCard(target, 1, 998, false, juhou.name, true, ".", "#tyt_hc__juhou_ask")
    if #cards > 0 then
      self.cost_data = {cards = cards, tos = {target.id}}
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    player:broadcastSkillInvoke(juhou.name)
    target:addToPile("$tyt_hc__juhou", self.cost_data.cards, false, juhou.name, target.id, nil)
    data.extra_data = data.extra_data or {}
    data.extra_data.tyt_hc__juhou = data.extra_data.tyt_hc__juhou or {}
    table.insert(data.extra_data.tyt_hc__juhou, {target.id, self.cost_data.cards})
  end,
}

local juhou_delay = fk.CreateTriggerSkill{
  name = "#tyt_hc__juhou_delay",
  anim_type = "defensive",
  frequency = Skill.Compulsory,
  events = {fk.CardUseFinished},
  can_trigger = function(self, event, target, player, data)
    data.extra_data = data.extra_data or {}
    data.extra_data.tyt_hc__juhou = data.extra_data.tyt_hc__juhou or {}
    for _, t in ipairs(data.extra_data.tyt_hc__juhou) do
      if t[1] == player.id then
        for _, cid in ipairs(t[2]) do
          if player:getPileNameOfId(cid) == "$tyt_hc__juhou" then
            return true
          end
        end
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    data.extra_data = data.extra_data or {}
    data.extra_data.tyt_hc__juhou = data.extra_data.tyt_hc__juhou or {}
    local cards = {}
    for _, t in ipairs(data.extra_data.tyt_hc__juhou) do
      if t[1] == player.id then
        for _, cid in ipairs(t[2]) do
          if player:getPileNameOfId(cid) == "$tyt_hc__juhou" then
            table.insert(cards, cid)
          end
        end
      end
    end
    room:obtainCard(player, cards, false, fk.ReasonPrey, player.id, self.name)
  end,
}

shibao:addCompanions("tyt_hc_heg__n_simayif")
juhou:addRelatedSkill(juhou_trigger)
juhou:addRelatedSkill(juhou_delay)
shibao:addSkill(zhuosheng)
shibao:addSkill(juhou)

Fk:loadTranslationTable{
  ["tyt_hc_heg__n_shibao"] = "石苞",
  ["#tyt_hc_heg__n_shibao"] = "乐陵郡公",
  ["illustrator:tyt_hc_heg__n_shibao"] = "凝聚永恒",
  ["tyt_hc__zhuosheng"] = "擢升",
  [":tyt_hc__zhuosheng"] = "每回合每种牌名限一次，你可以将至少两张手牌当一张基本牌使用，然后你摸X张牌（X为其中带有“合纵”的牌数）。",
  ["tyt_hc__juhou"] = "拒后",
  [":tyt_hc__juhou"] = "阵法技，与你处于同一队列的角色成为【杀】或普通锦囊牌的目标后，其可以将任意张手牌扣置于武将牌上，结算完成后，其获得之。",

  ["#tyt_hc__juhou_trigger"] = "拒后",
  ["#tyt_hc__juhou_delay"] = "拒后",
  ["#tyt_hc__juhou_ask"] = "拒后：你可将任意张手牌扣置于武将牌上直到此牌结算完毕",
  ["$tyt_hc__juhou"] = "拒后",

  ["$tyt_hc__zhuosheng1"] = "才经世务，干用之绩。",
  ["$tyt_hc__zhuosheng2"] = "器量之远，当至公辅。",
  ["$tyt_hc__juhou1"] = "",
  ["$tyt_hc__juhou2"] = "",

  ["~tyt_hc_heg__n_shibao"] = "寒门出身，难以擢升。",
}

local yanghuiyu = General(extension, "tyt_hc_heg__n_yanghuiyu", "jinz", 3, 3, General.Female)

local ciwei = fk.CreateTriggerSkill{
  name = "tyt_hc__ciwei",
  anim_type = "control",
  events = {fk.CardUsing},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self) and target ~= player and not player:isNude() and player.room:getCurrent() then
      local room = player.room
      local use_event = room.logic:getCurrentEvent():findParent(GameEvent.UseCard, true)
      if use_event == nil then return false end
      local mark = {}
      room.logic:getEventsOfScope(GameEvent.UseCard, 1, function(e)
        if e.id <= use_event.id then
          table.insert(mark, e.id)
          return false
        end
        return true
      end, Player.HistoryTurn)
      return #mark % 2 == 0
    end
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local cards = room:askForDiscard(player, 1, 1, true, self.name, true, ".",
    "#tyt_hc__ciwei-invoke::"..target.id..":"..data.card:toLogString(), true)
    if #cards > 0 then
      self.cost_data = {cards = cards, tos = {target.id}}
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:throwCard(self.cost_data.cards, self.name, player, player)
    data.tos = {}
    room:sendLog{ type = "#CardNullifiedBySkill", from = target.id, arg = self.name, arg2 = data.card:toLogString() }
    if data.card.type == Card.TypeEquip and room:getCardArea(data.card) == Card.Processing and not player.dead then
      local first = #(room.logic.event_recorder[GameEvent.MoveCards] or Util.DummyTable)
      room:obtainCard(player, data.card, true, fk.ReasonPrey, player.id, self.name)
      local e = HC.GetRecentMoveEventByskill(room, self.name, first)
      if e == nil then return end
      local tcards = {}
      for _, move in ipairs(e.data) do
        for _, info in ipairs(move.moveInfo) do
          table.insertIfNeed(tcards, info.cardId)
        end
      end
      tcards = U.moveCardsHoldingAreaCheck(room, tcards, e.id)
      tcards = table.filter(tcards, function (cid) return room:getCardOwner(cid) == player and room:getCardArea(cid) == Card.PlayerHand
      end)
      if #tcards > 0 and player:canUse(Fk:getCardById(tcards[1])) then
        room:useCard({from = player.id, tos = {{player.id}}, card = Fk:getCardById(tcards[1])}) --FIXME:先不管转化的装备以及对别人用的装备
      end
    end
  end,
}

local huirong = fk.CreateTriggerSkill{
  name = "tyt_hc__huirong",
  mute = true,
  events = {fk.DamageInflicted, fk.GeneralRevealed},
  can_trigger = function (self, event, target, player, data)
    if target ~= player or not player:hasSkill(self) or player:getMark(self.name) > 0 then return false end
    if event == fk.GeneralRevealed then
      for _, v in pairs(data) do
        if table.contains(Fk.generals[v]:getSkillNameList(), self.name) then return true end
      end
    else
      return player.phase == Player.NotActive and not player:hasShownSkill(self)
        and (table.contains(Fk.generals[H.getActualGeneral(player, false)]:getSkillNameList(), self.name)
        or table.contains(Fk.generals[H.getActualGeneral(player, true)]:getSkillNameList(), self.name))
    end
  end,
  on_cost =function (self, event, target, player, data)
    if event == fk.GeneralRevealed then
      return true
    else
      return player.room:askForSkillInvoke(player, self.name)
    end
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    if event == fk.DamageInflicted then
      room:notifySkillInvoked(player, self.name, "defensive")
      player:broadcastSkillInvoke(self.name)
      return true
    else
      room:addPlayerMark(player, self.name)

      local targets = table.filter(room.alive_players, function (p)
        return p:getHandcardNum() > p.hp or p:getHandcardNum() < p.hp
      end)
      if #targets > 0 then
        local victims = room:askForChoosePlayers(player, table.map(targets, Util.IdMapper), 1, 1, "#tyt_hc__huirong-choose", self.name)
        if #victims > 0 then
          player:broadcastSkillInvoke(self.name)
          local to = room:getPlayerById(victims[1])
          local n = to:getHandcardNum() - math.max(to.hp, 0)
          if n > 0 then
            room:notifySkillInvoked(player, self.name, "control", victims)
            room:askForDiscard(to, n, n, false, self.name, false)
          else
            if n < 0 then
              room:notifySkillInvoked(player, self.name, "drawcard", victims)
              to:drawCards(-n, self.name)
            end
          end
        end
      end
    end
  end,
}

yanghuiyu:addCompanions("tyt_hc_heg__n_simashi")
yanghuiyu:addSkill(ciwei)
yanghuiyu:addSkill(huirong)

Fk:loadTranslationTable{
  ["tyt_hc_heg__n_yanghuiyu"] = "羊徽瑜",
  ["#tyt_hc_heg__n_yanghuiyu"] = "景献皇后",
  ["illustrator:tyt_hc_heg__n_yanghuiyu"] = "Jzeo",

  ["tyt_hc__huirong"] = "慧容",
  [":tyt_hc__huirong"] = "当你于回合外受到伤害时，若你未明置过此武将牌，你可以明置此武将牌并防止此伤害；当你首次明置此武将牌后，你可以令一名角色将手牌摸至或弃置至其体力值。",
  ["tyt_hc__ciwei"] = "慈威",
  [":tyt_hc__ciwei"] = "其他角色于一回合内使用本回合第偶数张牌时，你可弃置一张牌取消所有目标，若此牌为装备牌，你获得并使用之。",

  ["#tyt_hc__ciwei-invoke"] = "慈威：你可以弃置一张牌，取消 %dest 使用的%arg",
  ["#tyt_hc__huirong-choose"] = "是否发动〖慧容〗，令一名角色将手牌摸或弃至体力值",

  ["$tyt_hc__huirong1"] = "红尘洗练，慧容不改。",
  ["$tyt_hc__huirong2"] = "花貌易改，福惠长存。",
  ["$tyt_hc__ciwei1"] = "乃家乃邦，是则是效。",
  ["$tyt_hc__ciwei2"] = "其慈有威，不舒不暴。",
  ["~tyt_hc_heg__n_yanghuiyu"] = "韶华易老，佳容不再……",
}

local wangyuanji = General(extension, "tyt_hc_heg__n_wangyuanji", "jinz", 3, 3, General.Female)

local yanxi = fk.CreateActiveSkill{
  name = "tyt_hc__yanxi",
  anim_type = "drawcard",
  card_num = 0,
  target_num = 1,
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) == 0
  end,
  card_filter = Util.FalseFunc,
  target_filter = function(self, to_select, selected, selected_cards, card, extra_data, player)
    return #selected == 0 and to_select ~= player.id and not Fk:currentRoom():getPlayerById(to_select):isKongcheng()
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local target = room:getPlayerById(effect.tos[1])
    local id = room:askForCardChosen(player, target, "h", self.name, "#tyt_hc__yanxi-choose")
    target:showCards(id)
    local cards = U.turnOverCardsFromDrawPile(player, 2, self.name)
    table.insert(cards, 1, id)
    if player.dead then room:cleanProcessingArea(cards, self.name) return end
    local choices = {}
    for _, color in ipairs({Card.Black, Card.Red}) do
      for _, cid in ipairs(cards) do
        local c = Fk:getCardById(cid)
        if c.color == color then
          table.insertIfNeed(choices, c:getColorString())
        end
      end
    end
    for _, type in ipairs({Card.TypeBasic, Card.TypeTrick, Card.TypeEquip}) do
      for _, cid in ipairs(cards) do
        local c = Fk:getCardById(cid)
        if c.type == type then
          table.insertIfNeed(choices, c:getTypeString())
        end
      end
    end
    if #choices == 0 then room:cleanProcessingArea(cards, self.name) end
    local result = U.askforViewCardsAndChoice(player, cards, choices, self.name, "#tyt_hc__yanxi-card")  --因为君刘章武，改为亮出
    local gets1, gets2 = {}, cards
    if result == "black" then
      gets1 = table.filter(cards, function (cid) return Fk:getCardById(cid).color == Card.Black end)
    elseif result == "red" then
      gets1 = table.filter(cards, function (cid) return Fk:getCardById(cid).color == Card.Red end)
    elseif result == "basic" then
      gets1 = table.filter(cards, function (cid) return Fk:getCardById(cid).type == Card.TypeBasic end)
    elseif result == "trick" then
      gets1 = table.filter(cards, function (cid) return Fk:getCardById(cid).type == Card.TypeTrick end)
    elseif result == "equip" then
      gets1 = table.filter(cards, function (cid) return Fk:getCardById(cid).type == Card.TypeEquip end)
    end
    local first = #(room.logic.event_recorder[GameEvent.MoveCards] or Util.DummyTable)
    room:obtainCard(player, gets1, true, fk.ReasonPrey, player.id, self.name)
    local e = HC.GetRecentMoveEventByskill(room, self.name, first)
    local x = 0
    if e ~= nil then
      for _, move in ipairs(e.data) do
        if move.to == player.id and move.toArea == Card.PlayerHand then
          x = x + #move.moveInfo
        end
      end
      gets2 = U.moveCardsHoldingAreaCheck(room, cards, e.id - 1)
    end
    if not target.dead then
      table.removeOne(gets2, id)
      room:obtainCard(target, gets2, true, fk.ReasonPrey, target.id, self.name)
    end
    if not player.dead then
      room:addPlayerMark(player, MarkEnum.AddMaxCardsInTurn, x)
    end
    room:cleanProcessingArea(cards, self.name)
  end,
}

local shiren = fk.CreateTriggerSkill{
  name = "tyt_hc__shiren",
  mute = true,
  events = {fk.DamageInflicted, fk.GeneralRevealed},
  can_trigger = function (self, event, target, player, data)
    if target ~= player or not player:hasSkill(self) or player:getMark(self.name) > 0 then return false end
    if event == fk.GeneralRevealed then
      for _, v in pairs(data) do
        if table.contains(Fk.generals[v]:getSkillNameList(), self.name) then return true end
      end
    else
      return player.phase == Player.NotActive and not player:hasShownSkill(self)
        and (table.contains(Fk.generals[H.getActualGeneral(player, false)]:getSkillNameList(), self.name)
        or table.contains(Fk.generals[H.getActualGeneral(player, true)]:getSkillNameList(), self.name))
    end
  end,
  on_cost = function (self, event, target, player, data)
    if event == fk.GeneralRevealed then
      return true
    else
      return player.room:askForSkillInvoke(player, self.name)
    end
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    if event == fk.DamageInflicted then
      room:notifySkillInvoked(player, self.name, "defensive")
      player:broadcastSkillInvoke(self.name)
      return true
    else
      room:addPlayerMark(player, self.name)

      local targets = table.filter(room.alive_players, function (p)
        return p ~= player and not p:isKongcheng()
      end)
      if #targets > 0 then
        local victims = room:askForChoosePlayers(player, table.map(targets, Util.IdMapper), 1, 1, "#tyt_hc__shiren-invoke", self.name)
        if #victims > 0 then
          room:notifySkillInvoked(player, self.name, "special", victims)
          player:broadcastSkillInvoke(self.name)
          Fk.skills["tyt_hc__yanxi"]:onUse(room, {from = player.id, tos = victims})
        end
      end
    end
  end,
}

wangyuanji:addCompanions("tyt_hc_heg__n_simazhaof")
wangyuanji:addSkill(yanxi)
wangyuanji:addSkill(shiren)

Fk:loadTranslationTable{
  ["tyt_hc_heg__n_wangyuanji"] = "王元姬",
  ["#tyt_hc_heg__n_wangyuanji"] = "文明皇后",
  ["illustrator:tyt_hc_heg__n_wangyuanji"] = "六道目",
  ["tyt_hc__shiren"] = "识人",
  [":tyt_hc__shiren"] = "当你于回合外受到伤害时，若你未明置过此武将牌，你可以明置此武将牌并防止此伤害；当你首次明置此武将牌后，你可以发动一次〖宴戏〗。",
  ["tyt_hc__yanxi"] = "宴戏",
  [":tyt_hc__yanxi"] = "出牌阶段限一次，你可以展示一名其他角色的一张手牌并亮出牌堆顶的两张牌，然后你获得其中一种颜色或类别的牌，其获得其余牌，本回合你的手牌上限+X（X为你此次获得的牌数）。",

  ["#tyt_hc__yanxi-choose"] = "宴戏:选择一张牌展示",
  ["#tyt_hc__yanxi-card"] = "宴戏:选择一种颜色或类别获得对应牌",
  ["#tyt_hc__shiren-invoke"] = "是否发动〖识人〗，对一名其他角色发动〖宴戏〗",

  ["$tyt_hc__shiren1"] = "宠过必乱，不可大任。",
  ["$tyt_hc__shiren2"] = "开卷有益，识人有法",
  ["$tyt_hc__yanxi1"] = "宴会嬉趣，其乐融融。",
  ["$tyt_hc__yanxi2"] = "宴中趣玩，得遇知己。",
  ["~tyt_hc_heg__n_wangyuanji"] = "祖父已逝，哀凄悲戚。",
}

local duyu = General(extension, "tyt_hc_heg__n_duyu", "jinz", 4)
duyu.mainMaxHpAdjustedValue = -1

local sanchen = fk.CreateActiveSkill{
  name = "tyt_hc__sanchen",
  anim_type = "support",
  card_num = 0,
  target_num = 1,
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) == 0
  end,
  card_filter = Util.FalseFunc,
  target_filter = function(self, to_select, selected)
    return #selected == 0 and Fk:currentRoom():getPlayerById(to_select):getMark("tyt_hc__sanchen-turn") == 0
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local target = room:getPlayerById(effect.tos[1])
    room:addPlayerMark(target, "tyt_hc__sanchen-turn", 1)
    target:drawCards(3, self.name)
    local cards = room:askForDiscard(target, 3, 3, true, self.name, false, ".", "#tyt_hc__sanchen-discard:"..player.id, true)
    local typeMap = {}
    for _, id in ipairs(cards) do
      typeMap[tostring(Fk:getCardById(id).type)] = (typeMap[tostring(Fk:getCardById(id).type)] or 0) + 1
    end
    room:throwCard(cards, self.name, target, target)
    for _, v in pairs(typeMap) do
      if v >= 2 then return end
    end
    room:addPlayerMark(player, "tyt_hc__sanchen-reset-turn")
    if not target.dead then
      target:drawCards(1, self.name)
    end
    player:setSkillUseHistory(self.name, 0, Player.HistoryPhase)
  end,
}

local pozhu = fk.CreateViewAsSkill{
  name = "tyt_hc__pozhu",
  anim_type = "offensive",
  relate_to_place = "m",
  prompt = "#tyt_hc__pozhu",
  handly_pile = true,
  times = function (self)
    return Self.phase == Player.Play and Self:getMark("tyt_hc__sanchen-reset-turn") - Self:usedSkillTimes(self.name, Player.HistoryPhase) or -1
  end,
  card_filter = function (self, to_select, selected, player)
    return #selected == 0 and table.contains(player:getHandlyIds(), to_select)
  end,
  view_as = function(self, cards)
    if #cards ~= 1 then return end
    local c = Fk:cloneCard("unexpectation")
    c.skillName = self.name
    c:addSubcard(cards[1])
    return c
  end,
  enabled_at_play = function (self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) < player:getMark("tyt_hc__sanchen-reset-turn")
  end,
}

duyu:addSkill(pozhu)
duyu:addSkill(sanchen)

Fk:loadTranslationTable{
  ["tyt_hc_heg__n_duyu"] = "杜预",
  ["#tyt_hc_heg__n_duyu"] = "文成武德",
  ["designer:tyt_hc_heg__n_duyu"] = "张浩",
  ["illustrator:tyt_hc_heg__n_duyu"] = "君桓文化",

  ["tyt_hc__sanchen"] = "三陈",
  [":tyt_hc__sanchen"] = "出牌阶段限一次，你可令一名角色摸三张牌然后弃置三张牌。若其未因此而弃置类别相同的牌，其摸一张牌，且本技能视为未发动过（每回合每名角色限一次）。",
  ["tyt_hc__pozhu"] = "破竹",
  [":tyt_hc__pozhu"] = "主将技，此武将牌减少半个阴阳鱼；出牌阶段限X次（X为你本回合重置〖三陈〗的次数），你可将一张手牌当【出其不意】使用。",

  ["#tyt_hc__sanchen-discard"] = "三陈：弃置三张牌，若类别各不相同则你摸一张牌且 %src 可以再发动〖三陈〗",
  ["#tyt_hc__pozhu"] = "破竹：你可将一张手牌当【出其不意】使用",

  ["$tyt_hc__sanchen1"] = "陈书弼国，当一而再、再而三。",
  ["$tyt_hc__sanchen2"] = "勘除弼事，三陈而就。",
  ["$tyt_hc__pozhu1"] = "攻其不备，摧枯拉朽！",
  ["$tyt_hc__pozhu2"] = "势如破竹，铁锁横江亦难挡！",
  ["~tyt_hc_heg__n_duyu"] = "金瓯尚缺，死难瞑目……",
}

local weiguan = General(extension, "tyt_hc_heg__n_weiguan", "jinz", 3)

local zhongyun = fk.CreateTriggerSkill{
  name = "tyt_hc__zhongyun",
  anim_type = "control",
  frequency = Skill.Compulsory,
  events = {fk.Damaged, fk.HpRecover, fk.AfterCardsMove},
  can_trigger = function(self, event, target, player, data)
    if event == fk.AfterCardsMove then
      if player:hasSkill(self) and player.hp == player:getHandcardNum() and player:getMark("tyt_hc__zhongyun2-turn") == 0 and player.room:getCurrent() then
        for _, move in ipairs(data) do
          if move.to == player.id and move.toArea == Card.PlayerHand then
            return true
          end
          for _, info in ipairs(move.moveInfo) do
            if move.from == player.id and info.fromArea == Card.PlayerHand then
              return true
            end
          end
        end
      end
    else
      return target == player and player:hasSkill(self) and player.hp == player:getHandcardNum() and player:getMark("tyt_hc__zhongyun1-turn") == 0
        and (player:isWounded() or table.find(player.room:getOtherPlayers(player, false), function (p) return player:inMyAttackRange(p) end))
        and player.room:getCurrent()
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.AfterCardsMove then
      room:setPlayerMark(player, "tyt_hc__zhongyun2-turn", 1)
      local targets = table.filter(room:getOtherPlayers(player, false), function (p) return not p:isNude() end)
      if #targets > 0 then
        local to = room:askForChoosePlayers(player, table.map(targets, Util.IdMapper), 1, 1, "#tyt_hc__zhongyun-discard", self.name, true)
        if #to > 0 then
          local id = room:askForCardChosen(player, room:getPlayerById(to[1]), "he", self.name)
          room:throwCard({id}, self.name, room:getPlayerById(to[1]), player)
          return
        end
      end
      player:drawCards(1, self.name)
    else
      room:setPlayerMark(player, "tyt_hc__zhongyun1-turn", 1)
      local targets = table.filter(room:getOtherPlayers(player, false), function (p) return player:inMyAttackRange(p) end)
      if #targets > 0 then
        local to = room:askForChoosePlayers(player, table.map(targets, Util.IdMapper), 1, 1, "#tyt_hc__zhongyun-damage", self.name,
        player:isWounded())
        if #to > 0 then
          room:damage{
            from = player,
            to = room:getPlayerById(to[1]),
            damage = 1,
            skillName = self.name,
          }
          return
        end
      end
      if player:isWounded() then
        room:recover({
          who = player,
          num = 1,
          recoverBy = player,
          skillName = self.name
        })
      end
    end
  end,
}

local shenpin = fk.CreateTriggerSkill{
  name = "tyt_hc__shenpin",
  anim_type = "control",
  events = {fk.AskForRetrial},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and not player:isNude() and data.card.color ~= Card.NoColor
  end,
  on_cost = function(self, event, target, player, data)
    local suit = data.card.color == Card.Black and "heart,diamond" or "spade,club"
    local pattern = ".|.|"..suit
    if data.reason == "#eight_diagram_skill" and data.who == player then --处理判八卦阵不能用此八卦改判
      local id = player:getEquipment(Card.SubtypeArmor)
      if id and Fk:getCardById(id).trueName == "eight_diagram" then
        pattern = pattern.. "|.|.|.|^"..id
      end
    end
    local card = player.room:askForCard(player, 1, 1, true, self.name, true, pattern, "#tyt_hc__shenpin-invoke::"..target.id, player:getHandlyIds(false)) --允许马车
    if #card > 0 then
      self.cost_data = card[1]
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    player.room:retrial(Fk:getCardById(self.cost_data), player, data, self.name, false)
  end,
}

weiguan:addSkill(zhongyun)
weiguan:addSkill(shenpin)

Fk:loadTranslationTable{
  ["tyt_hc_heg__n_weiguan"] = "卫瓘",
  ["#tyt_hc_heg__n_weiguan"] = "兰陵郡公",
  ["illustrator:tyt_hc_heg__n_weiguan"] = "Karneval",

  ["tyt_hc__zhongyun"] = "忠允",
  [":tyt_hc__zhongyun"] = "锁定技，每回合各限一次，当你受到伤害或回复体力后，若你的体力值与你的手牌数相等，你回复1点体力或对你攻击范围内的一名角色造成1点伤害；"..
  "当你获得或失去手牌后，若你的体力值与你的手牌数相等，你摸一张牌或弃置一名其他角色的一张牌。",
  ["tyt_hc__shenpin"] = "神品",
  [":tyt_hc__shenpin"] = "当一名角色的判定牌生效前，你可以打出一张与判定牌颜色不同的牌代替之。",

  ["#tyt_hc__zhongyun-damage"] = "忠允：对攻击范围内一名角色造成1点伤害，或点“取消”回复1点体力",
  ["#tyt_hc__zhongyun-discard"] = "忠允：弃置一名其他角色的一张牌，或点“取消”摸一张牌",
  ["#tyt_hc__shenpin-invoke"] = "神品：你可以打出一张不同颜色的牌代替 %dest 的判定",

  ["$tyt_hc__zhongyun1"] = "秉公行事，无所亲疏。",
  ["$tyt_hc__zhongyun2"] = "明晰法理，通晓人情。",
  ["$tyt_hc__shenpin1"] = "考其遗法，肃若神明。",
  ["$tyt_hc__shenpin2"] = "气韵生动，出于天成。",
  ["~tyt_hc_heg__n_weiguan"] = "辞荣善终，不可求……",
}

local jiachong = General(extension, "tyt_hc_heg__n_jiachong", "jinz", 3)

local xiongshu = fk.CreateTriggerSkill{
  name = "tyt_hc__xiongshu",
  events = {fk.TargetSpecified},
  can_trigger = function(self, event, target, player, data)
   if player:hasSkill(self) and player:usedSkillTimes(self.name) == 0 and data.firstTarget then
    local card = data.card
    return (card.trueName == "slash" or card.type == Card.TypeTrick and card.is_damage_card) and (player == target or not player:isNude()) and player.room:getCurrent()
   end
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    if player == target then
      local tos = room:askForChoosePlayers(player, table.map(room:getOtherPlayers(player), Util.IdMapper), 1, 1, "#tyt_hc__xiongshu-other", self.name)
      if #tos > 0 then
        self.cost_data = {tos = tos, cards = nil}
        return true
      end
    else
      local cards = room:askForDiscard(player, 1, 1, true, self.name, true, ".", "#tyt_hc__xiongshu-self", true)
      if #cards > 0 then
        self.cost_data = {tos = {player.id}, cards = cards}
        return true
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if self.cost_data.cards then
      room:throwCard(self.cost_data.cards, self.name, player)
    else
      player:drawCards(1, self.name)
    end
    data.extra_data = data.extra_data or {}
    data.extra_data.tytxiongshu = self.cost_data.tos[1]
    data.extra_data.huoshou = nil
  end,

  refresh_events = {fk.PreDamage},
  can_refresh = function(self, event, target, player, data)
    if data.card then
      local e = player.room.logic:getCurrentEvent():findParent(GameEvent.UseCard)
      if e then
        local use = e.data[1]
        return use.extra_data and use.extra_data.tytxiongshu and not use.extra_data.huoshou
      end
    end
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    local e = room.logic:getCurrentEvent():findParent(GameEvent.UseCard)
    if e then
      local use = e.data[1]
      data.from = room:getPlayerById(use.extra_data.tytxiongshu)
    end
  end,
}

local jianhui = fk.CreateTriggerSkill{
  name = "tyt_hc__jianhui",
  events = {fk.Damage},
  anim_type = "control",
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and data.from and not data.from.dead and H.compareKingdomWith(data.from, data.to)
  end,
  on_cost = function(self, event, target, player, data)
    local tos = player.room:askForChoosePlayers(player, {data.from.id, data.to.id}, 1, 1, "#tyt_hc__jianhui", self.name)
    if #tos > 0 then
      table.insertTableIfNeed(tos, {data.from.id, data.to.id})
      self.cost_data = {tos = tos}
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:getPlayerById(self.cost_data.tos[1]):drawCards(1,self.name)
    local victimid = self.cost_data.tos[2]
    if victimid then
      local victim = room:getPlayerById(victimid)
      local card = room:askForCardChosen(player, victim, "he", self.name)
      if card then
        room:throwCard(card, self.name, victim, player)
      end
    end
  end,
}

jiachong:addCompanions("tyt_hc_heg__n_simazhaof")
jiachong:addSkill(xiongshu)
jiachong:addSkill(jianhui)

Fk:loadTranslationTable{
  ["tyt_hc_heg__n_jiachong"] = "贾充",
  ["#tyt_hc_heg__n_jiachong"] = "鲁郡公",
  ["illustrator:tyt_hc_heg__n_jiachong"] = "游漫美绘",

  ["tyt_hc__xiongshu"] = "凶竖",
  [":tyt_hc__xiongshu"] = "每回合限一次，你/其他角色使用牌指定目标后，你可以摸一张牌并令一名其他角色成为此牌的伤害来源/弃置一张牌并成为此牌的伤害来源。",
  ["tyt_hc__jianhui"] = "奸回",
  [":tyt_hc__jianhui"] = "一名角色对与其势力相同的角色造成伤害后，你可以令来源或受伤角色摸一张牌，然后你弃置其中另一名角色一张牌。",

  ["#tyt_hc__xiongshu-other"] = "凶竖：你可选择一名其他角色，其成为伤害来源且你摸一张牌",
  ["#tyt_hc__xiongshu-self"] = "凶竖：你可弃置一张牌，你成为伤害来源",
  ["#tyt_hc__jianhui"] = "奸回：你可令来源或受伤角色摸一张牌",

  ["$tyt_hc__xiongshu1"] = "怀志拥权，谁敢不服？",
  ["$tyt_hc__xiongshu2"] = "天下凶凶，由我一人。",
  ["$tyt_hc__jianhui1"] = "一箭之仇，十年不忘！",
  ["$tyt_hc__jianhui2"] = "此仇不报，怨恨难消！",
  ["~tyt_hc_heg__n_jiachong"] = "任元褒，吾与汝势不两立！",
}

local yanghu = General(extension, "tyt_hc_heg__n_yanghu", "jinz", 4)

local chongxin = fk.CreateActiveSkill{
  name = "tyt_hc__chongxin",
  prompt = "#tyt_hc__chongxin-active",
  anim_type = "drawcard",
  card_num = 0,
  target_num = 1,
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) == 0
  end,
  card_filter = Util.FalseFunc,
  target_filter = function(self, to_select, selected, selected_cards, card, extra_data, player)
    return #selected == 0 and (H.compareKingdomWith(Fk:currentRoom():getPlayerById(to_select), player, true)
      or Fk:currentRoom():getPlayerById(to_select).kingdom == "unknown")
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local target = room:getPlayerById(effect.tos[1])
    local ae = Fk:cloneCard("await_exhausted")
    if not player:prohibitUse(ae) then
      room:useVirtualCard("await_exhausted", {}, player, {player, target}, self.name)
    end
  end,
}

local weishu = fk.CreateActiveSkill{
  name = "tyt_hc__weishu",
  prompt = function (self)
    return (Self:getSwitchSkillState(self.name, false) == fk.SwitchYang and "#tyt_hc__weishu-yang:::" or "#tyt_hc__weishu-yin:::")..
      math.max(1, math.min(Self:getMark("@tyt_hc__weishu-lastround"), Self.maxHp))
  end,
  anim_type = "switch",
  switch_skill_name = "tyt_hc__weishu",
  target_num = 0,
  max_round_use_time = 1,
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryRound) < 1
  end,
  card_filter =function (self, to_select, selected, player)
    if player:getSwitchSkillState(self.name, false) == fk.SwitchYang then
      return #selected < math.max(1, math.min(player:getMark("@tyt_hc__weishu-lastround"), player.maxHp))
    else
      return false
    end
  end,
  target_filter = Util.FalseFunc,
  feasible = function (self, selected, selected_cards, player)
    if player:getSwitchSkillState(self.name, false) == fk.SwitchYang then
      return #selected_cards == math.max(1, math.min(player:getMark("@tyt_hc__weishu-lastround"), player.maxHp))
    else
      return true
    end
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local isYang = player:getSwitchSkillState(self.name, true) == fk.SwitchYang
    if isYang then
      room:throwCard(effect.cards, self.name, player)
      room:setPlayerMark(player, "@tyt_hc__weishu-yang-round", {#effect.cards, "tyt_hc__weishu-draw", 0})
    else
      local x = math.max(1, math.min(player:getMark("@tyt_hc__weishu-lastround"), player.maxHp))
      player:drawCards(x)
      room:setPlayerMark(player, "@tyt_hc__weishu-yin-round", {x, "tyt_hc__weishu-discard", 0})
    end
  end,
}

local weishu_delay = fk.CreateTriggerSkill{
  name = "#tyt_hc__weishu_delay",
  events = {fk.AfterCardsMove},
  mute = true,
  frequency = Skill.Compulsory,
  can_trigger = function(self, event, target, player, data)
    for _, move in ipairs(data) do
      if move.to == player.id and move.toArea == Card.PlayerHand and #player:getTableMark("@tyt_hc__weishu-yang-round") > 0
        and player.phase ~= Player.Draw and move.skillName ~= weishu.name and not player.dead then
        return true
      end
      if move.from == player.id and #player:getTableMark("@tyt_hc__weishu-yin-round") > 0
        and (move.to ~= player.id or (move.toArea ~= Card.PlayerHand and move.toArea ~= Card.PlayerEquip)) and
        player.phase ~= Player.Discard and move.skillName ~= weishu.name and not player.dead and
        table.find(player:getCardIds("he"), function (id) return not player:prohibitDiscard(Fk:getCardById(id)) end) then
        for _, info in ipairs(move.moveInfo) do
          if info.fromArea == Card.PlayerHand or info.fromArea == Card.PlayerEquip then
            return true
          end
        end
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    player:broadcastSkillInvoke(weishu.name)
    local yang = player:getTableMark("@tyt_hc__weishu-yang-round")
    if #yang > 0 then
      room:notifySkillInvoked(player, weishu.name, "drawcard")
      yang[3] = yang[3] + 1
      room:setPlayerMark(player, "@tyt_hc__weishu-yang-round", yang)
      player:drawCards(1, weishu.name)
    end
    local yin = player:getTableMark("@tyt_hc__weishu-yin-round")
    if #yin > 0 then
      room:notifySkillInvoked(player, weishu.name, "negative")
      yin[3] = yin[3] + 1
      room:setPlayerMark(player, "@tyt_hc__weishu-yin-round", yin)
      room:askForDiscard(player, 1, 1, true, weishu.name, false)
    end
  end,

  refresh_events = {fk.AfterRoundEnd},
  can_refresh = function(self, event, target, player, data)
    return #player:getTableMark("@tyt_hc__weishu-yang-round") > 0 or #player:getTableMark("@tyt_hc__weishu-yin-round") > 0
      or player:getMark("@tyt_hc__weishu-lastround") > 0
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    room:setPlayerMark(player, "@tyt_hc__weishu-lastround", 0)
    local yang = player:getTableMark("@tyt_hc__weishu-yang-round")
    if #yang > 0 then
      room:setPlayerMark(player, "@tyt_hc__weishu-lastround", math.abs(yang[1] - yang[3]))
    end
    local yin = player:getTableMark("@tyt_hc__weishu-yin-round")
    if #yin > 0 then
      room:setPlayerMark(player, "@tyt_hc__weishu-lastround", math.abs(yin[1] - yin[3]))
    end
  end,
}

yanghu:addCompanions("tyt_hc_heg__n_duyu")
weishu:addRelatedSkill(weishu_delay)
yanghu:addSkill(chongxin)
yanghu:addSkill(weishu)

Fk:loadTranslationTable{
  ["tyt_hc_heg__n_yanghu"] = "羊祜",
  ["#tyt_hc_heg__n_yanghu"] = "执德清劭",
  ["illustrator:tyt_hc_heg__n_yanghu"] = "匠人绘",

  ["tyt_hc__chongxin"] = "崇信",
  [":tyt_hc__chongxin"] = "出牌阶段限一次，你可以选择一名与其他势力角色，视为对你与其使用【以逸待劳】（无目标限制）。",
  ["tyt_hc__weishu"] = "卫戍",
  [":tyt_hc__weishu"] = "转换技，每轮限一次，出牌阶段，阳：你可以弃置X张牌，本轮你于摸牌阶段外不因此技能而获得牌后，你摸一张牌；"..
  "阴：你可以摸X张牌，本轮你于弃牌阶段外不因此技能而失去牌后，你弃置一张牌。（X为你上一轮因此技能获得与弃置的牌数差且至少为1，至多为你的体力上限）",
  [":tyt_hc__weishu_yang"] = "转换技，每轮限一次，出牌阶段，<font color=\"#E0DB2F\">阳：你可以弃置X张牌，本轮你于摸牌阶段外不因此技能而获得牌后，你摸一张牌；"..
  "</font>阴：你可以摸X张牌，本轮你于弃牌阶段外不因此技能而失去牌后，你弃置一张牌。（X为你上一轮因此技能获得与弃置的牌数差且至少为1，至多为你的体力上限）",
  [":tyt_hc__weishu_yin"] = "转换技，每轮限一次，出牌阶段，阳：你可以弃置X张牌，本轮你于摸牌阶段外不因此技能而获得牌后，你摸一张牌；<font color=\"#E0DB2F\">"..
  "阴：你可以摸X张牌，本轮你于弃牌阶段外不因此技能而失去牌后，你弃置一张牌。</font>（X为你上一轮因此技能获得与弃置的牌数差且至少为1，至多为你的体力上限）",
  ["#tyt_hc__weishu_delay"] = "卫戍",

  ["#tyt_hc__chongxin-active"] = "发动 崇信，选择一名其他势力角色",
  ["#tyt_hc__weishu-yang"] = "发动 卫戍，弃置%arg张牌，本轮你于摸牌阶段外不因此技能而获得牌后，你摸一张牌",
  ["#tyt_hc__weishu-yin"] = "发动 卫戍，摸%arg张牌，本轮你于弃牌阶段外不因此技能而失去牌后，你弃置一张牌",
  ["@tyt_hc__weishu-yang-round"] = "卫戍 弃",
  ["tyt_hc__weishu-draw"] = "摸",
  ["@tyt_hc__weishu-yin-round"] = "卫戍 摸",
  ["tyt_hc__weishu-discard"] = "弃",
  ["@tyt_hc__weishu-lastround"] = "卫戍 上轮差",

  ["$tyt_hc__chongxin1"] = "非诚不行，无信不立。",
  ["$tyt_hc__chongxin2"] = "以诚待人，可得其心。",
  ["$tyt_hc__weishu1"] = "水来土掩，兵来将挡。",
  ["$tyt_hc__weishu2"] = "吴人来犯，当用心戒备。",
  ["~tyt_hc_heg__n_yanghu"] = "当断不断，反受其乱……",
}

local yangzhi = General(extension, "tyt_hc_heg__n_yangzhi", "jinz", 3, 3, General.Female)

local wanyi = fk.CreateViewAsSkill{
  name = "tyt_hc__wanyi",
  prompt = "#tyt_hc__wanyi",
  handly_pile = true,
  interaction = function(self, player)
    local all_names = {"chasing_near", "unexpectation", "drowning", "foresight"}
    local names = table.simpleClone(all_names)
    for _, name in ipairs(all_names) do
      if table.contains(player:getTableMark("tyt_hc__wanyi-turn"), name) then
        table.removeOne(names, name)
      end
    end
    if #names == 0 then return end
    return UI.ComboBox {choices = names, all_choices = all_names,}
  end,
  card_filter = function (self, to_select, selected)
    return #selected == 0 and hasMark(Fk:getCardById(to_select), "@@alliance", MarkEnum.CardTempMarkSuffix)
  end,
  before_use = function (self, player, use)
    local mark = player:getTableMark("tyt_hc__wanyi-turn")
    table.insert(mark, use.card.name)
    player.room:setPlayerMark(player, "tyt_hc__wanyi-turn", mark)
  end,
  view_as = function(self, cards)
    if #cards ~= 1 or not self.interaction.data then return end
    local card = Fk:cloneCard(self.interaction.data)
    card:addSubcard(cards[1])
    card.skillName = self.name
    return card
  end,
}

local maihuo = fk.CreateTriggerSkill{
  name = "tyt_hc__maihuo",
  mute = true,
  derived_piles = "tyt_hc__maihuo_huo",
  events = {fk.TargetConfirming, fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    if not player:hasSkill(self) then return false end
    if event == fk.TargetConfirming then
      return data.card.trueName == "slash" and (not data.card:isVirtual() or #data.card.subcards > 0) and player.room:getCurrent()
        and player:getMark("tyt_hc__maihuo-turn") == 0 and H.compareKingdomWith(player, target)
    elseif event == fk.EventPhaseStart then
      return target ~= player and target.phase == Player.Play and #player:getPile("tyt_hc__maihuo_huo") > 0 and target:inMyAttackRange(player) and not target.dead
    end
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    if event == fk.TargetConfirming then
      room:addPlayerMark(player, "tyt_hc__maihuo-turn")
      if room:askForSkillInvoke(player, self.name, nil, "#tyt_hc__maihuo-invoke::"..data.to..":"..data.card:toLogString()) then
        self.cost_data = {tos = {target.id}}
        return true
      end
    elseif event == fk.EventPhaseStart then
      self.cost_data = {tos = {target.id}}
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    player:broadcastSkillInvoke(self.name)
    if event == fk.TargetConfirming then
      room:notifySkillInvoked(player, self.name, "defensive", self.cost_data.tos)
      AimGroup:cancelTarget(data, target.id)
      --处理青龙刀
      if target:getMark("@@sa__blade") > 0 then
        local usedata = room.logic:getCurrentEvent():findParent(GameEvent.UseCard).data[1]
        usedata.extra_data = usedata.extra_data or {}
        if usedata.extra_data.sa__bladeRevealProhibited then
          local num = usedata.extra_data.sa__bladeRevealProhibited[tostring(target.id)]
          room:removePlayerMark(target, "@@sa__blade", num)
          usedata.extra_data.sa__bladeRevealProhibited[tostring(target.id)] = nil
          local record = target:getTableMark(MarkEnum.RevealProhibited)
          table.removeOne(record, "m")
          table.removeOne(record, "d")
          if #record == 0 then record = 0 end
          room:setPlayerMark(target, MarkEnum.RevealProhibited, record)
        end
      end
      if room:getCardArea(data.card) == Card.Processing then
        player:addToPile("tyt_hc__maihuo_huo", data.card, true, self.name)
      end
      return true
    elseif event == fk.EventPhaseStart then
      room:notifySkillInvoked(player, self.name, "negative", self.cost_data.tos)
      local huos = player:getPile("tyt_hc__maihuo_huo")
      local card = room:askForCard(target, 1, 1, false, self.name, false, ".|.|.|.|.|.|"..table.concat(huos, ","), "#tyt_hc__maihuo-effect::"..player.id, huos)
      if not card then return end
      room:moveCards({
        from = player.id,
        ids = card,
        toArea = Card.DiscardPile,
        moveReason = fk.ReasonPutIntoDiscardPile,
        skillName = self.name,
      })
      if not target.dead and target:canUseTo(Fk:cloneCard("slash"), player, {bypass_times = true}) then
        local slash = Fk:cloneCard("slash")
        slash.skillName = self.name
        local use = { from = target.id, tos = { { player.id } }, card = slash, extraUse = true,
          extra_data = { bypass_times = true, tyt_hc__maihuo_target = player.id } }
        room:useCard(use)
      end
    end
  end,
}

local maihuo_delay = fk.CreateTriggerSkill{
  name = "#tyt_hc__maihuo_delay",
  events = {fk.DamageInflicted},
  can_trigger = function(self, event, target, player, data)
    if player == target and data.card.trueName == "slash" and table.contains(data.card.skillNames, maihuo.name) and data.damage >= player.hp then
      local e = player.room.logic:getCurrentEvent():findParent(GameEvent.UseCard)
      if e then
        local use = e.data[1]
        return use.extra_data and use.extra_data.tyt_hc__maihuo_target == player.id
      end
    end
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    player:broadcastSkillInvoke(maihuo.name)
    local room = player.room
    if table.contains(Fk.generals[H.getActualGeneral(player, false)]:getSkillNameList(), maihuo.name) then
      H.removeGeneral(room, player, false)
    elseif table.contains(Fk.generals[H.getActualGeneral(player, true)]:getSkillNameList(), maihuo.name) then
      H.removeGeneral(room, player, true)
    end
    return true
  end,
}

maihuo:addRelatedSkill(maihuo_delay)
yangzhi:addSkill(wanyi)
yangzhi:addSkill(maihuo)

Fk:loadTranslationTable{
  ["tyt_hc_heg__n_yangzhi"] = "杨芷",
  ["#tyt_hc_heg__n_yangzhi"] = "武悼皇后",
  ["illustrator:tyt_hc_heg__n_yangzhi"] = "游漫美绘",

  ["tyt_hc__wanyi"] = "婉嫕",
  [":tyt_hc__wanyi"] = "出牌阶段每种牌名限一次，你可以将一张带有“合纵”的牌当【逐近弃远】、【出其不意】、【水淹七军】或【洞烛先机】使用。",
  ["#tyt_hc__wanyi"] = "婉嫕：你可以将一张带有“合纵”的牌当一种应变篇锦囊使用",
  ["tyt_hc__maihuo"] = "埋祸",
  [":tyt_hc__maihuo"] = "每回合限一次，与你势力相同的角色成为非虚拟【杀】的目标时，你可以取消之，然后将此【杀】置于武将牌上，称为“祸”；"..
    "其他角色的出牌阶段开始时，若你在其攻击范围内，其移去一张“祸”，视为对你使用【杀】，你受到此【杀】造成的致命伤害时，防止此伤害并移除此武将牌。",

  ["tyt_hc__maihuo_huo"] = "祸",
  ["#tyt_hc__maihuo-invoke"] = "埋祸：你可以取消对 %dest 使用的%arg",
  ["#tyt_hc__maihuo-effect"] = "埋祸：移去一张“祸”，视为对 %dest 使用【杀】",
  ["#tyt_hc__maihuo_delay"] = "埋祸",

  ["$tyt_hc__wanyi1"] = "天性婉嫕，易以道御。",
  ["$tyt_hc__wanyi2"] = "婉嫕利珍，为后攸行。",
  ["$tyt_hc__maihuo1"] = "祸根未决，转而滋蔓。",
  ["$tyt_hc__maihuo2"] = "无德之亲，终为祸根。",
  ["~tyt_hc_heg__n_yangzhi"] = "贾氏……构陷……",
}

local zuofen = General(extension, "tyt_hc_heg__n_zuofen", "jinz", 3, 3, General.Female)

local zhaosong = fk.CreateActiveSkill{
  name = "tyt_hc__zhaosong",
  prompt = "#tyt_hc__zhaosong2-active",
  anim_type = "big",
  card_num = 0,
  target_num = 1,
  can_use = function(self, player)
    return not table.contains(player:getTableMark("@tyt_hc__zhaosong"), 2)
  end,
  card_filter = Util.FalseFunc,
  target_filter = function(self, to_select, selected, selected_cards, card, extra_data, player)
    if #selected == 0 and to_select ~= player.id then
      local target = Fk:currentRoom():getPlayerById(to_select)
      return not target:isKongcheng() or target.general == "anjiang" or target.deputyGeneral == "anjiang"
    end
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local target = room:getPlayerById(effect.tos[1])
    room:addTableMark(player, "@tyt_hc__zhaosong", 2)
    if H.getGeneralsRevealedNum(target) ~= 2 then
      local general = {target.general == "anjiang" and target:getMark("__heg_general") or target.general,
        target.deputyGeneral == "anjiang" and target:getMark("__heg_deputy") or target.deputyGeneral, target.seat}
      room:askForCustomDialog(player, self.name, "packages/new_heg/qml/KnownBothBox.qml", general)
    end
    if not target:isAllNude() then
      local card_data = {}
      if #target:getCardIds(Player.Hand) > 0 then
        table.insert(card_data, {"$Hand", target:getCardIds(Player.Hand)})
      end
      if #target:getCardIds(Player.Equip) > 0 then
        table.insert(card_data, {"$Equip", target:getCardIds(Player.Equip)})
      end
      if #target:getCardIds(Player.Judge) > 0 then
        table.insert(card_data, {"$Judge", target:getCardIds(Player.Judge)})
      end
      local cards = room:askForPoxi(player, "tyt_hc__zhaosong2", card_data, nil, true)
      if #cards == 0 then return end
      room:obtainCard(player, cards, false, fk.ReasonPrey, player.id, self.name)
    end
  end,
}

Fk:addPoxiMethod{
  name = "tyt_hc__zhaosong2",
  card_filter = function(to_select, selected, data)
    return #selected == 0
  end,
  feasible = function(selected)
    return #selected == 1
  end,
  prompt = function ()
    return "#tyt_hc__zhaosong2-ask"
  end
}

local zhaosong_trigger = fk.CreateTriggerSkill{
  name = "#tyt_hc__zhaosong_trigger",
  main_skill = zhaosong,
  mute = true,
  events = {fk.EnterDying, fk.TargetSpecifying},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self.main_skill) then
      if event == fk.EnterDying then
        return not table.contains(player:getTableMark("@tyt_hc__zhaosong"), 1) and not target.dead and target.hp < 1
      else
        return not table.contains(player:getTableMark("@tyt_hc__zhaosong"), 3) and data.card.trueName == "slash" and data.firstTarget
          and #AimGroup:getAllTargets(data.tos) == 1 and #player.room:getUseExtraTargets(data, true, true) > 0
      end
    end
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    if event == fk.EnterDying then
      self.cost_data = {}
      return room:askForSkillInvoke(player, self.main_skill.name, nil, "#tyt_hc__zhaosong1-invoke::"..target.id)
    else
      local tos = room:askForChoosePlayers(player, room:getUseExtraTargets(data, true), 1, 2,
        "#tyt_hc__zhaosong3-invoke", self.main_skill.name, true)
      if #tos > 0 then
        self.cost_data = {tos = tos}
        return true
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    player:broadcastSkillInvoke(self.main_skill.name)
    room:notifySkillInvoked(player, self.main_skill.name, "big", self.cost_data.tos)
    if event == fk.EnterDying then
      room:addTableMark(player, "@tyt_hc__zhaosong", 1)
      room:recover({
        who = target,
        num = 2 - target.hp,
        recoverBy = player,
        skillName = self.main_skill.name
      })
      if not target.dead then
        target:drawCards(1, self.main_skill.name)
      end
    else
      room:addTableMark(player, "@tyt_hc__zhaosong", 3)
      for _, id in ipairs(self.cost_data.tos) do
        AimGroup:addTargets(room, data, id)
      end
      -- 处理青龙刀
      local usedata = room.logic:getCurrentEvent():findParent(GameEvent.UseCard).data[1]
      if usedata.extra_data and usedata.extra_data.sa__bladeRevealProhibited then
        for _, id in ipairs(self.cost_data.tos) do
          local p = room:getPlayerById(id)
          room:addPlayerMark(p, "@@sa__blade")
          local record = p:getTableMark(MarkEnum.RevealProhibited)
          table.insertTable(record, {"m", "d"})
          room:setPlayerMark(p, MarkEnum.RevealProhibited, record)
          data.extra_data = data.extra_data or {}
          data.extra_data.sa__bladeRevealProhibited = data.extra_data.sa__bladeRevealProhibited or {}
          data.extra_data.sa__bladeRevealProhibited[tostring(id)] = (data.extra_data.sa__bladeRevealProhibited[tostring(id)] or 0) + 1
        end
      end
    end
  end,
}

local lisi = fk.CreateTriggerSkill{
  name = "tyt_hc__lisi",
  --anim_type = "big",
  events = {fk.Death},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and H.compareKingdomWith(player, target) and #player:getTableMark("@tyt_hc__zhaosong") > 0
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local allchoices = {"tyt_hc__lisi1", "tyt_hc__lisi2", "tyt_hc__lisi3", "Cancel"}
    local choices = {}
    for i = 1, 3, 1 do
      if table.contains(player:getTableMark("@tyt_hc__zhaosong"), i) then
        table.insert(choices, allchoices[i])
      end
    end
    table.insert(choices, "Cancel")
    local choice = room:askForChoice(player, choices, self.name, "#tyt_hc__lisi", false, allchoices)
    if choice ~= "Cancel" then
      self.cost_data = tonumber(choice:sub(-1))
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:removeTableMark(player, "@tyt_hc__zhaosong", self.cost_data)
  end,
}

zhaosong:addRelatedSkill(zhaosong_trigger)
zuofen:addSkill(zhaosong)
zuofen:addSkill(lisi)

Fk:loadTranslationTable{
  ["tyt_hc_heg__n_zuofen"] = "左棻",
  ["#tyt_hc_heg__n_zuofen"] = "无宠的才女",
  ["illustrator:tyt_hc_heg__n_zuofen"] = "明暗交界",

  ["tyt_hc__zhaosong"] = "诏颂",
  [":tyt_hc__zhaosong"] = "每局游戏每项限一次，1.一名角色进入濒死状态时，你可以令其回复体力至2点并摸一张牌；"..
  "2.出牌阶段，你可以观看一名其他角色所有暗置的武将牌和手牌，然后你可以获得其区域内的一张牌；"..
  "3.一名角色使用【杀】指定唯一目标时，你可以为此【杀】增加至多两个额外目标。",
  ["tyt_hc__lisi"] = "离思",
  [":tyt_hc__lisi"] = "与你势力相同的角色死亡时，你可以令〖诏颂〗中的一项视为未发动过。",

  ["@tyt_hc__zhaosong"] = "诏颂",
  ["#tyt_hc__zhaosong_trigger"] = "诏颂",
  ["tyt_hc__zhaosong2"] = "诏颂",
  ["#tyt_hc__zhaosong1-invoke"] = "诏颂：你可以令 %dest 回复体力至2点并摸一张牌",
  ["#tyt_hc__zhaosong3-invoke"] = "诏颂：你可以为此【杀】增加至多两个目标",
  ["#tyt_hc__zhaosong2-active"] = "发动 诏颂，观看一名其他角色的武将牌和手牌",
  ["#tyt_hc__zhaosong2-ask"] = "诏颂：你可以选择一张牌获得",
  ["tyt_hc__lisi1"] = "重置 濒死回复",
  ["tyt_hc__lisi2"] = "重置 观看牌",
  ["tyt_hc__lisi3"] = "重置 增加目标",
  ["#tyt_hc__lisi"] = "离思：你可以令〖诏颂〗中的一项视为未发动过",

  ["$tyt_hc__zhaosong1"] = "领诏者，可上而颂之。",
  ["$tyt_hc__zhaosong2"] = "今为诏，以上告下也。",
  ["$tyt_hc__lisi1"] = "骨肉至亲，化为他人。",
  ["$tyt_hc__lisi2"] = "梦想魂归，见所思兮。",
  ["~tyt_hc_heg__n_zuofen"] = "惨怆愁悲……",
}

local zhongyan = General(extension, "tyt_hc_heg__n_zhongyan", "jinz", 3, 3, General.Female)

local bolan = fk.CreateActiveSkill{
  name = "tyt_hc__bolan",
  anim_type = "special",
  card_num = 0,
  target_num = 0,
  attached_skill_name = "tyt_hc__bolan&",
  prompt = "#tyt_hc__bolan",
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) == 0
  end,
  card_filter = Util.FalseFunc,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local general = table.random(room.general_pile)
    room:sendLog{
      type = "#tyt_hc__bolan-show",
      from = player.id,
      arg = general,
      toast = true,
    }
    room:askForCustomDialog(player, self.name,
      "packages/utility/qml/ChooseGeneralsAndChoiceBox.qml", {
        {general},
        {},
        "#tyt_hc__bolan-choose",
        {"OK"},
        0,
        0
      })
    local g = Fk.generals[general]
    if not g then return end
    local skilltable = {wei = "tyt_hc__bolan_qice", shu = "tyt_hc__bolan_tiaoxin", wu = "tyt_hc__bolan_zhiheng",
      qun = "tyt_hc__bolan_chuli", jinz = "tyt_hc__bolan_sanchen"}
    if g.kingdom then
      local skill = skilltable[g.kingdom]
      if skill then
        room:addTableMark(player, "@tyt_hc__bolan-phase", skill)
        room:handleAddLoseSkills(player, skill)
        room.logic:getCurrentEvent():findParent(GameEvent.Phase):addCleaner(function()
          room:handleAddLoseSkills(player, "-"..skill)
        end)
      end
    end
    if g.subkingdom then
      local skill = skilltable[g.subkingdom]
      if skill then
        room:addTableMark(player, "@tyt_hc__bolan-phase", skill)
        room:handleAddLoseSkills(player, skill)
        room.logic:getCurrentEvent():findParent(GameEvent.Phase):addCleaner(function()
          room:handleAddLoseSkills(player, "-"..skill)
        end)
      end
    end
  end,
}

local bolan_active = fk.CreateActiveSkill{
  name = "tyt_hc__bolan&",
  anim_type = "special",
  card_num = 0,
  target_num = 0,
  prompt = "#tyt_hc__bolan-other",
  can_use = function(self, player)
    return table.find(Fk.currentRoom().alive_players, function(p)
      return p ~= player and p:hasSkill(bolan) and p:getMark(self.name.."-phase") == 0
    end)
  end,
  card_filter = Util.FalseFunc,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    player:broadcastSkillInvoke(bolan.name)
    local zhongyans = table.filter(room:getOtherPlayers(player), function(p)
      return p:hasSkill(bolan) and p:getMark(self.name.."-phase") == 0
    end)
    local zhongyanp = zhongyans[1]
    if #zhongyans > 1 then
      local ps =room:askForChoosePlayers(player, table.map(zhongyans, Util.IdMapper), 1, 1, nil, bolan.name, false)
      zhongyanp = room:getPlayerById(ps[1])
    else
      room:doIndicate(player.id, {zhongyanp.id})
    end
    room:addPlayerMark(zhongyanp, self.name.."-phase")
    Fk.skills["tyt_hc__bolan"]:onUse(room, effect)
    if player.hp > zhongyanp.hp then
      room:loseHp(player, 1, bolan.name)
    end
  end,
}

local qice = fk.CreateActiveSkill{
  name = "tyt_hc__bolan_qice",
  prompt = "#tyt_hc__bolan_qice-active",
  interaction = function(self, player)
    local handcards = player:getCardIds(Player.Hand)
    local names, all_names = {} , {}
    for _, id in ipairs(Fk:getAllCardIds()) do
      local card = Fk:getCardById(id)
      if card:isCommonTrick() and not card.is_derived and not table.contains(all_names, card.name) then
        table.insert(all_names, card.name)
        local to_use = Fk:cloneCard(card.name)
        to_use:addSubcards(handcards)
        if player:canUse(to_use) and not player:prohibitUse(to_use) then
          local x = 0
          if to_use.multiple_targets and to_use.skill:getMinTargetNum() == 0 then
            for _, p in ipairs(Fk:currentRoom().alive_players) do
              if not player:isProhibited(p, card) and card.skill:modTargetFilter(p.id, {}, player, card, true) then
                x = x + 1
              end
            end
          end
          if x <= player:getHandcardNum() then
            table.insert(names, card.name)
          end
        end
      end
    end
    if #names == 0 then return end
    return UI.ComboBox {choices = names, all_choices = all_names}
  end,
  card_num = 0,
  min_target_num = 0,
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) == 0 and not player:isKongcheng()
  end,
  card_filter = Util.FalseFunc,
  target_filter = function(self, to_select, selected, selected_cards, _, _, player)
    if self.interaction.data == nil then return false end
    local to_use = Fk:cloneCard(self.interaction.data)
    to_use.skillName = self.name
    to_use:addSubcards(player:getCardIds(Player.Hand))
    if not to_use.skill:targetFilter(to_select, selected, selected_cards, to_use, Util.DummyTable, player) then return false end
    if (#selected == 0 or to_use.multiple_targets) and
    player:isProhibited(Fk:currentRoom():getPlayerById(to_select), to_use) then return false end
    if to_use.multiple_targets then
      if #selected >= player:getHandcardNum() then return false end
      if to_use.skill:getMaxTargetNum(player, to_use) == 1 then
        local x = 0
        for _, p in ipairs(Fk:currentRoom().alive_players) do
          if p.id == to_select or (not player:isProhibited(p, to_use) and to_use.skill:modTargetFilter(p.id, {to_select}, player, to_use, true)) then
            x = x + 1
          end
        end
        if x > player:getHandcardNum() then return false end
      end
    end
    return true
  end,
  feasible = function(self, selected, selected_cards, player)
    if self.interaction.data == nil then return false end
    local to_use = Fk:cloneCard(self.interaction.data)
    to_use.skillName = self.name
    to_use:addSubcards(player:getCardIds(Player.Hand))
    return to_use.skill:feasible(selected, selected_cards, player, to_use)
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local card = Fk:cloneCard(self.interaction.data)
    card:addSubcards(player:getCardIds(Player.Hand))
    card.skillName = self.name
    local use = {
      from = player.id,
      tos = table.map(effect.tos, function (id)
        return {id}
      end),
      card = card,
    }
    room:useCard(use)
    if not player.dead and player:getMark("@@tyt_hc__bolan_qice_transform") == 0 and room:askForChoice(player, {"transform_deputy", "Cancel"}, self.name) ~= "Cancel" then
      room:setPlayerMark(player, "@@tyt_hc__bolan_qice_transform", 1)
      H.transformGeneral(room, player)
    end
  end,
}

local tiaoxin = fk.CreateActiveSkill{
  name = "tyt_hc__bolan_tiaoxin",
  anim_type = "control",
  card_num = 0,
  target_num = 1,
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) == 0
  end,
  card_filter = Util.FalseFunc,
  target_filter =function (self, to_select, selected, selected_cards, card, extra_data, player)
    return #selected == 0 and Fk:currentRoom():getPlayerById(to_select):inMyAttackRange(player)
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local target = room:getPlayerById(effect.tos[1])
    local use = room:askForUseCard(target, "slash", "slash", "#tyt_hc__bolan_tiaoxin-use::"..player.id, true, {include_targets = {player.id}})
    if use then
      room:useCard(use)
    else
      if not target:isNude() then
        local card = room:askForCardChosen(player, target, "he", self.name)
        room:throwCard({card}, self.name, target, player)
      end
    end
  end
}

local zhiheng = fk.CreateActiveSkill{
  name = "tyt_hc__bolan_zhiheng",
  anim_type = "drawcard",
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) == 0
  end,
  target_num = 0,
  min_card_num = 1,
  max_card_num = function()
    return table.find(Self:getEquipments(Card.SubtypeTreasure), function(cid)
      return Fk:getCardById(cid).name == "luminous_pearl"
    end) and 998 or Self.maxHp
  end,
  card_filter = function(self, to_select, selected, player)
    if #selected >= player.maxHp then
      return table.find(player:getEquipments(Card.SubtypeTreasure), function(cid)
        return Fk:getCardById(cid).name == "luminous_pearl" and not table.contains(selected, cid) and to_select ~= cid
      end)
    end
    return #selected < player.maxHp and not player:prohibitDiscard(Fk:getCardById(to_select))
  end,
  on_use = function(self, room, effect)
    local from = room:getPlayerById(effect.from)
    room:throwCard(effect.cards, self.name, from, from)
    if not from.dead then
      from:drawCards(#effect.cards, self.name)
    end
  end,
}

local zhiheng_refresh = fk.CreateTriggerSkill{ -- 处理定澜夜明珠
  name = "#tyt_hc__bolan_zhiheng_refresh",

  refresh_events = {fk.EventLoseSkill, fk.EventAcquireSkill},
  can_refresh = function(self, event, target, player, data)
    return player == target and data == Fk.skills["tyt_hc__bolan_zhiheng"] and table.find(player:getEquipments(Card.SubtypeTreasure), function(cid)
      return Fk:getCardById(cid).name == "luminous_pearl"
    end)
  end,
  on_refresh = function(self, event, target, player, data)
    player.room:handleAddLoseSkills(player, event == fk.EventAcquireSkill and "-luminous_pearl_skill" or "luminous_pearl_skill", nil, false, true)
  end,
}

local chuli = fk.CreateActiveSkill{
  name = "tyt_hc__bolan_chuli",
  anim_type = "control",
  card_num = 0,
  min_target_num = 1,
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) == 0 and not player:isNude()
  end,
  card_filter = Util.FalseFunc,
  target_filter = function(self, to_select, selected, selected_cards, card, extra_data, player)
    local room = Fk:currentRoom()
    local target = room:getPlayerById(to_select)
    return to_select ~= player.id and not target:isNude() and #selected < 3 and
      table.every(selected, function(id) return not H.compareKingdomWith(target, room:getPlayerById(id)) end)
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local targets = table.clone(effect.tos)
    table.insert(targets, 1, effect.from)
    room:sortPlayersByAction(targets)
    for _, id in ipairs(targets) do
      local target = room:getPlayerById(id)
      if not target:isNude() then
        local c = room:askForCardChosen(player, target, "he", self.name)
        room:throwCard({c}, self.name, target, player)
      end
    end
    for _, id in ipairs(targets) do
      local target = room:getPlayerById(id)
      if target:getMark("_tyt_hc__bolan_chuli-phase") > 0 and not target.dead then
        room:setPlayerMark(target, "_tyt_hc__bolan_chuli-phase", 0)
        target:drawCards(1, self.name)
      end
    end
  end,
}

local chuli_record = fk.CreateTriggerSkill{
  name = "#tyt_hc__bolan_chuli_record",
  mute = true,
  priority = 0.09,
  frequency = Skill.Compulsory,
  events = {fk.BeforeCardsMove},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self, true, true) then
      for _, move in ipairs(data) do
        if move.skillName == "tyt_hc__bolan_chuli" and move.moveReason == fk.ReasonDiscard then
          for _, info in ipairs(move.moveInfo) do
            if Fk:getCardById(info.cardId).suit == Card.Spade then
              self.cost_data = move.from
              return true
            end
          end
        end
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:addPlayerMark(room:getPlayerById(self.cost_data), "_tyt_hc__bolan_chuli-phase", 1)
  end,
}

local bolan_sanchen = fk.CreateActiveSkill{
  name = "tyt_hc__bolan_sanchen",
  anim_type = "support",
  card_num = 0,
  target_num = 1,
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) == 0
  end,
  card_filter = Util.FalseFunc,
  target_filter = function(self, to_select, selected)
    return #selected == 0 and Fk:currentRoom():getPlayerById(to_select):getMark("tyt_hc__bolan_sanchen-turn") == 0
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local target = room:getPlayerById(effect.tos[1])
    room:addPlayerMark(target, "tyt_hc__bolan_sanchen-turn", 1)
    target:drawCards(3, self.name)
    local cards = room:askForDiscard(target, 3, 3, true, self.name, false, ".", "#tyt_hc__bolan_sanchen-discard:"..player.id, true)
    local typeMap = {}
    for _, id in ipairs(cards) do
      typeMap[tostring(Fk:getCardById(id).type)] = (typeMap[tostring(Fk:getCardById(id).type)] or 0) + 1
    end
    room:throwCard(cards, self.name, target, target)
    for _, v in pairs(typeMap) do
      if v >= 2 then return end
    end
    room:addPlayerMark(player, "tyt_hc__sanchen-reset-turn")
    if not target.dead then
      target:drawCards(1, self.name)
    end
    player:setSkillUseHistory(self.name, 0, Player.HistoryPhase)
  end,
}

local yifa = fk.CreateTriggerSkill{
  name = "tyt_hc__yifa",
  anim_type = "defensive",
  frequency = Skill.Compulsory,
  events = {fk.TargetConfirmed},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and target == player and data.from ~= player.id and (data.card.trueName == "slash" or
      (data.card.color == Card.Black and data.card:isCommonTrick())) and player.room:getCurrent() and not player.room:getCurrent().dead
    end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local to = room.current
    room:doIndicate(player.id, {to.id})
    room:addPlayerMark(to, "@tyt_hc__yifa-turn", 1)
    room:addPlayerMark(to, MarkEnum.MinusMaxCardsInTurn, 1)
    room:broadcastProperty(to, "MaxCards")
  end,
}

Fk:addSkill(bolan_active)
Fk:addSkill(qice)
Fk:addSkill(tiaoxin)
zhiheng:addRelatedSkill(zhiheng_refresh)
Fk:addSkill(zhiheng)
chuli:addRelatedSkill(chuli_record)
Fk:addSkill(chuli)
Fk:addSkill(bolan_sanchen)
zhongyan:addSkill(bolan)
zhongyan:addSkill(yifa)

Fk:loadTranslationTable{
  ["tyt_hc_heg__n_zhongyan"] = "钟琰",
  ["#tyt_hc_heg__n_zhongyan"] = "聪慧弘雅",
  ["illustrator:tyt_hc_heg__n_zhongyan"] = "明暗交界",

  ["tyt_hc__bolan"] = "博览",
  [":tyt_hc__bolan"] = "每名角色的出牌阶段限一次，其可以展示一张未加入游戏的武将牌，根据此武将牌的势力获得技能直到此阶段结束："..
    "魏-〖奇策〗；蜀-〖挑衅〗；吴-〖制衡〗；群-〖除疠〗；晋-〖三陈〗，然后若体力值大于你，其失去一点体力。",
  ["tyt_hc__yifa"] = "仪法",
  [":tyt_hc__yifa"] = "锁定技，当你成为其他角色使用【杀】或黑色普通锦囊牌的目标后，当前回合角色本回合手牌上限-1。",
  ["tyt_hc__bolan&"] = "博览",
  [":tyt_hc__bolan&"] = "出牌阶段限一次，你可以展示一张未加入游戏的武将牌，根据此武将牌的势力获得技能："..
    "魏-〖奇策〗；蜀-〖挑衅〗；吴-〖制衡〗；群-〖除疠〗；晋-〖三陈〗，然后若你的体力值大于钟琰，你失去一点体力。",

  ["#tyt_hc__bolan"] = "博览：你可以展示一张未加入游戏的武将牌并获得技能",
  ["#tyt_hc__bolan-other"] = "博览：你可以展示一张未加入游戏的武将牌并获得技能，若你的体力值大于钟琰，你失去一点体力",
  ["@tyt_hc__bolan-phase"] = "博览",
  ["@tyt_hc__yifa-turn"] = "仪法",
  ["#tyt_hc__bolan-show"] = "%from 发动〖博览〗，展示武将牌 %arg",
  ["#tyt_hc__bolan-choose"] = "博览：展示武将牌",

  ["tyt_hc__bolan_qice"] = "奇策",
  [":tyt_hc__bolan_qice"] = "出牌阶段限一次，你可将所有手牌当任意一张普通锦囊牌使用，你不能以此法使用目标数大于X的牌（X为你的手牌数），然后你可变更副将。<font color='grey'><small>此为【奇策（博览）】</small></font>",
  ["#tyt_hc__bolan_qice-active"] = "发动 奇策，将所有手牌当一张锦囊牌使用",
  ["@@tyt_hc__bolan_qice_transform"] = "奇策 已变更",
  ["tyt_hc__bolan_tiaoxin"] = "挑衅",
  [":tyt_hc__bolan_tiaoxin"] = "出牌阶段限一次，你可以选择一名你在其攻击范围内的角色，其需包括你在内的角色使用一张【杀】，否则你弃置其一张牌。<font color='grey'><small>此为【挑衅（博览）】</small></font>",
  ["#tyt_hc__bolan_tiaoxin-use"] = "挑衅：对 %dest 使用杀，否则被 %dest 弃置一张牌",
  ["tyt_hc__bolan_zhiheng"] = "制衡",
  [":tyt_hc__bolan_zhiheng"] = "出牌阶段限一次，你可弃置至多X张牌（X为你的体力上限），然后你摸等量的牌。<font color='grey'><small>此为【制衡（博览）】</small></font>",
  ["tyt_hc__bolan_chuli"] = "除疠",
  [":tyt_hc__bolan_chuli"] = "出牌阶段限一次，你可选择至多三名势力各不相同或未确定势力的其他角色，然后你弃置你和这些角色的各一张牌。被弃置♠牌的角色各摸一张牌。<font color='grey'><small>此为【除疠（博览）】</small></font>",
  ["tyt_hc__bolan_sanchen"] = "三陈",
  [":tyt_hc__bolan_sanchen"] = "出牌阶段限一次，你可令一名角色摸三张牌然后弃置三张牌。若其未因此而弃置类别相同的牌，其摸一张牌，且本技能视为未发动过（每回合每名角色限一次）。<font color='grey'><small>此为【三陈（博览）】</small></font>",
  ["#tyt_hc__bolan_sanchen-discard"] = "三陈：弃置三张牌，若类别各不相同则你摸一张牌且 %src 可以再发动〖三陈〗",

  ["$tyt_hc__bolan1"] = "博览群书，融会贯通。",
  ["$tyt_hc__bolan2"] = "博览于文，约之以礼。",
  ["$tyt_hc__yifa1"] = "仪法不明，则实不称名。",
  ["$tyt_hc__yifa2"] = "仪法明晰，则长治久安。",
  ["~tyt_hc_heg__n_zhongyan"] = "嗟尔姜任，邈不我留。",
}

local yangyan = General(extension, "tyt_hc_heg__n_yangyan", "jinz", 3, 3, General.Female)

local xuanbei = fk.CreateTriggerSkill{
  name = "tyt_hc__xuanbei",
  mute = true,
  events = {fk.GeneralRevealed, fk.CardUseFinished, fk.Death},
  can_trigger = function(self, event, target, player, data)
    if event == fk.Death then
      return player:hasSkill(self, false, true) and target == player
    else
      if player:hasSkill(self) and target == player then
        if event == fk.GeneralRevealed then
          if target ~= player or player:getMark(self.name) > 0 then return false end
          for _, v in pairs(data) do
            if table.contains(Fk.generals[v]:getSkillNameList(), self.name) then return true end
          end
        elseif event == fk.CardUseFinished then
          return not data.card:isVirtual() and hasMark(data.card, "@@alliance", MarkEnum.CardTempMarkSuffix) and player:getMark(self.name.."-turn") == 0
        end
      end
    end
  end,
  on_cost = function(self, event, target, player, data)
    if event == fk.GeneralRevealed then
      self.cost_data = {tos = nil}
      return true
    elseif event == fk.CardUseFinished then
      local to = player.room:askForChoosePlayers(player, table.map(player.room:getOtherPlayers(player, false), Util.IdMapper),
        1, 1, "#tyt_hc__xuanbei-give:::"..data.card:toLogString(), self.name, true)
      if #to > 0 then
        self.cost_data = {tos = to}
        return true
      end
    elseif event == fk.Death then
      local to = player.room:askForChoosePlayers(player, table.map(player.room:getOtherPlayers(player, false), Util.IdMapper),
        1, 1, "#tyt_hc__xuanbei-trans", self.name, true)
      if #to > 0 then
        self.cost_data = {tos = to}
        return true
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    player:broadcastSkillInvoke(self.name)
    if event == fk.GeneralRevealed then
      room:addPlayerMark(player, self.name)
      room:notifySkillInvoked(player, self.name, "drawcard")
      player:drawCards(2, self.name)
      if room:getCurrent() then
        room:addPlayerMark(player, "@@tyt_hc__xuanbei-turn")
      end
    elseif event == fk.CardUseFinished then
      room:addPlayerMark(player, self.name.."-turn")
      room:notifySkillInvoked(player, self.name, "support", self.cost_data.tos)
      room:moveCardTo(data.card, Card.PlayerHand, room:getPlayerById(self.cost_data.tos[1]), fk.ReasonGive, self.name, nil, true, player.id)
    elseif event == fk.Death then
      room:notifySkillInvoked(player, self.name, "special", self.cost_data.tos)
      H.transformGeneral(room, room:getPlayerById(self.cost_data.tos[1]))
    end
  end,
}

local xuanbei_delay = fk.CreateTriggerSkill{
  name = "#tyt_hc__xuanbei_delay",
  anim_type = "drawcard",
  frequency = Skill.Compulsory,
  events = {fk.CardUsing},
  can_trigger = function(self, event, target, player, data)
    return player:getMark("@@tyt_hc__xuanbei-turn") > 0 and target == player and not data.card:isVirtual()
      and hasMark(data.card, "@@alliance", MarkEnum.CardTempMarkSuffix)
  end,
  on_use = function(self, event, target, player, data)
    player:broadcastSkillInvoke(xuanbei.name)
    player:drawCards(1, xuanbei.name)
  end,
}

local xianwan = fk.CreateViewAsSkill{
  name = "tyt_hc__xianwan",
  pattern = "slash,jink",
  anim_type = "defensive",
  prompt = function()
    if Self.chained then
      return "#tyt_hc__xianwan-slash"
    else
      return "#tyt_hc__xianwan-jink"
    end
  end,
  card_filter = Util.FalseFunc,
  view_as = function(self, cards, player)
    local card
    if player:hasSkill(self) then
      if player.chained then
        card = Fk:cloneCard("slash")
      else
        card = Fk:cloneCard("jink")
      end
    end
    card.skillName = self.name
    return card
  end,
  before_use = function(self, player, use)
    if player.chained then
      player:setChainState(false)
    else
      player:setChainState(true)
    end
  end,
  enabled_at_play = function (self, player)
    return player.chained
  end,
  enabled_at_response = function (self, player, response)
    return Fk.currentResponsePattern and Exppattern:Parse(Fk.currentResponsePattern):match(Fk:cloneCard(player.chained and "slash" or "jink"))
  end,
}

yangyan:addCompanions("tyt_hc_heg__n_yangzhi")
xuanbei:addRelatedSkill(xuanbei_delay)
yangyan:addSkill(xuanbei)
yangyan:addSkill(xianwan)

Fk:loadTranslationTable{
  ["tyt_hc_heg__n_yangyan"] = "杨艳",
  ["#tyt_hc_heg__n_yangyan"] = "武元皇后",
  ["illustrator:tyt_hc_heg__n_yangyan"] = "游漫美绘",

  ["tyt_hc__xuanbei"] = "选备",
  [":tyt_hc__xuanbei"] = "当你首次明置此武将牌后，你摸两张牌，本回合你使用带有“合纵”的牌时摸一张牌。每回合限一次，当你使用带有“合纵”的牌结算后，你可以将之交给一名其他角色；你死亡时，你可以令一名其他角色变更副将。",
  ["tyt_hc__xianwan"] = "娴婉",
  [":tyt_hc__xianwan"] = "你可以横置，视为使用或打出一张【闪】；你可以重置，视为使用或打出一张【杀】。",

  ["@@tyt_hc__xuanbei-turn"] = "选备",
  ["#tyt_hc__xuanbei_delay"] = "选备",
  ["#tyt_hc__xuanbei-give"] = "选备：你可以将 %arg 交给一名其他角色",
  ["#tyt_hc__xuanbei-trans"] = "选备：你可以令一名其他角色变更副将",
  ["#tyt_hc__xianwan-slash"] = "娴婉：你可以重置，视为使用或打出一张【杀】",
  ["#tyt_hc__xianwan-jink"] = "娴婉：你可以横置，视为使用或打出一张【闪】",

  ["$tyt_hc__xuanbei1"] = "博选良家，以充后宫。",
  ["$tyt_hc__xuanbei2"] = "非良家，不可选也。",
  ["$tyt_hc__xianwan1"] = "婉而从物，不竞不争。",
  ["$tyt_hc__xianwan2"] = "娴婉恭谨，重贤加礼。",
  ["~tyt_hc_heg__n_yangyan"] = "一旦殂损，痛悼伤怀……",
}

local xuangongzhu = General(extension, "tyt_hc_heg__n_xuangongzhu", "jinz", 3, 3, General.Female)

local qimei = fk.CreateTriggerSkill{
  name = "tyt_hc__qimei",
  anim_type = "support",
  events = {fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and player.phase == Player.Start
  end,
  on_cost = function(self, event, target, player, data)
    local tos = player.room:askForChoosePlayers(player, table.map(player.room:getOtherPlayers(player, false), Util.IdMapper),
    1, 1, "#tyt_hc__qimei-choose", self.name, true)
    if #tos > 0 then
      self.cost_data = {tos = tos}
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local to = room:getPlayerById(self.cost_data.tos[1])
    room:addTableMark(to, "@@tyt_hc__qimei-turn", player.id)
    room:setPlayerMark(player, "tyt_hc__qimei_couple-turn", to.id)
  end,
}
local qimei_delay = fk.CreateTriggerSkill{
  name = "#tyt_hc__qimei_delay",
  events = {fk.AfterCardsMove, fk.Damaged, fk.HpLost, fk.HpRecover},
  anim_type = "support",
  can_trigger = function(self, event, target, player, data)
    local room = player.room
    if room:getCurrent() ~= player or player:usedSkillTimes(qimei.name) == 0 or player.dead then return false end
    local mark_id = player:getMark("tyt_hc__qimei_couple-turn")
    if mark_id == 0 then return false end
    local to = room:getPlayerById(mark_id)
    if to == nil or to.dead then return false end
    if event == fk.AfterCardsMove then
      if player:getHandcardNum() ~= to:getHandcardNum() then return false end
      local tos, tos2  = {player.id, mark_id}, {}
      for _, move in ipairs(data) do
        if move.from and table.contains(tos, move.from) and table.find(move.moveInfo, function (info)
          return info.fromArea == Card.PlayerHand
        end) then
          table.insert(tos2, move.from)
        end
        if move.to and table.contains(tos, move.to) and move.toArea == Card.PlayerHand then
          table.insert(tos2, move.to)
        end
      end
      tos2 = table.filter(tos2, function (p) return room:getPlayerById(p):isWounded() end)
      if #tos2 == 0 then return false end
      self.cost_data = {tos = tos2}
      return true
    else
      if player.hp ~= to.hp then return false end
      if target == player then
        self.cost_data = {tos = {player.id}}
        return true
      elseif target == to then
        self.cost_data = {tos = {to.id}}
        return true
      end
    end
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local tos = table.simpleClone(self.cost_data.tos)
    room:sortPlayersByAction(tos)
    player:broadcastSkillInvoke(qimei.name)
    if event == fk.AfterCardsMove then
      for _, pid in ipairs(tos) do
        local p = room:getPlayerById(pid)
        if not p.dead and p:isWounded() then
          room:recover({
            who = p,
            num = 1,
            recoverBy = player,
            skillName = qimei.name
          })
        end
      end
    else
      for _, pid in ipairs(tos) do
        local p = room:getPlayerById(pid)
        if not p.dead then
          room:drawCards(p, 1, qimei.name)
        end
      end
    end
  end,
}
local zhuijix = fk.CreateTriggerSkill{
  name = "tyt_hc__zhuijix",
  anim_type = "drawcard",
  events = {fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and player.phase == Player.Play
  end,
  on_cost = function (self, event, target, player, data)
    local room = player.room
    local allchoices = {"tyt_hc__zhuiji_recover-phase", "tyt_hc__zhuiji_draw-phase", "Cancel"}
    local choices = table.simpleClone(allchoices)
    if not player:isWounded() then
      table.removeOne(choices, "tyt_hc__zhuiji_recover-phase")
    end
    local choice = room:askForChoice(player, choices, self.name)
    if choice ~= "Cancel" then
      self.cost_data = choice
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local choice = self.cost_data
    local room = player.room
    room:addPlayerMark(player, choice, 1)
    if choice == "tyt_hc__zhuiji_recover-phase" then
      room:recover({
        who = player,
        num = 1,
        recoverBy = player,
        skillName = self.name
      })
    else
      player:drawCards(2, self.name)
    end
  end,
}
local zhuijix_trigger = fk.CreateTriggerSkill{
  name = "#tyt_hc__zhuijix_trigger",
  mute = true,
  events = {fk.EventPhaseEnd},
  can_trigger = function(self, event, target, player, data)
    return target == player and player.phase == Player.Play and player:usedSkillTimes("tyt_hc__zhuijix", Player.HistoryPhase) > 0
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    local room = player.room
    player:broadcastSkillInvoke("tyt_hc__zhuijix")
    room:notifySkillInvoked(player, "tyt_hc__zhuijix", "negative")
    if player:getMark("tyt_hc__zhuiji_recover-phase") > 0 then
      room:setPlayerMark(player, "tyt_hc__zhuiji_recover-phase", 0)
      room:askForDiscard(player, 2, 2, true, "tyt_hc__zhuijix", false)
    end
    if player:getMark("tyt_hc__zhuiji_draw-phase") > 0 then
      room:setPlayerMark(player, "tyt_hc__zhuiji_draw-phase", 0)
      room:loseHp(player, 1, "tyt_hc__zhuijix")
    end
  end,
}
qimei:addRelatedSkill(qimei_delay)
zhuijix:addRelatedSkill(zhuijix_trigger)
xuangongzhu:addSkill(qimei)
xuangongzhu:addSkill(zhuijix)
Fk:loadTranslationTable{
  ["tyt_hc_heg__n_xuangongzhu"] = "宣公主",
  ["#tyt_hc_heg__n_xuangongzhu"] = "高陵公主",
  ["illustrator:tyt_hc_heg__n_xuangongzhu"] = "凡果",

  ["tyt_hc__qimei"] = "齐眉",
  [":tyt_hc__qimei"] = "准备阶段，你可以选择一名其他角色，本回合你或其受到伤害、失去体力或回复体力后，若与另一名角色体力值相等，该角色摸一张牌，本回合你或其获得或失去手牌后，若与另一名角色手牌数相等，该角色回复一点体力。",
  ["tyt_hc__zhuijix"] = "追姬",
  [":tyt_hc__zhuijix"] = "出牌阶段开始时，你可以选择一项：1.回复1点体力，此阶段结束时弃置两张牌；2.摸两张牌，此阶段结束时失去1点体力。",
  ["#tyt_hc__qimei-choose"] = "齐眉：你可指定一名其他角色为“齐眉”角色",
  ["@@tyt_hc__qimei-turn"] = "齐眉",
  ["#tyt_hc__qimei_delay"] = "齐眉",
  ["tyt_hc__zhuiji_recover-phase"] = "回复1点体力，此阶段结束时弃两张牌",
  ["tyt_hc__zhuiji_draw-phase"] = "摸两张牌，此阶段结束时失去1点体力",

  ["$tyt_hc__qimei1"] = "辅车相依，比翼双飞。",
  ["$tyt_hc__qimei2"] = "情投意合，相濡以沫。",
  ["$tyt_hc__zhuijix1"] = "不过是些微代价罢了。",
  ["$tyt_hc__zhuijix2"] = "哼，以为这就能难倒我吗？",
  ["~tyt_hc_heg__n_xuangongzhu"] = "元凯，我去也……",
}

local xinchang = General(extension, "tyt_hc_heg__n_xinchang", "jinz", 3)
local canmou = fk.CreateTriggerSkill{
  name = "tyt_hc__canmou",
  events = {fk.TargetSpecifying},
  can_trigger = function(self, event, target, player, data)
    local room = player.room
    if player:hasSkill(self) and data.card:isCommonTrick() and data.card.trueName ~= "threaten_emperor" and data.firstTarget and room:getCurrent() and
      table.every(room:getOtherPlayers(target),
        function (p) return target:getHandcardNum() >= p:getHandcardNum()
      end) then
      local tos = {}
      local targets = room:getUseExtraTargets(data, true, true)
      local origin_targets = U.getActualUseTargets(room, data, event)
      if #origin_targets > 1 and player:getMark("tyt_hc__canmou-cancel-turn") == 0 then
        table.insertTable(tos, origin_targets)
      end
      if #targets > 0 and player:getMark("tyt_hc__canmou-add-turn") == 0 then
        table.insertTable(tos, targets)
      end
      if #tos > 0 then
        self.cost_data = tos
        return true
      end
    end
  end,
  on_cost = function(self, event, target, player, data)
    local to = player.room:askForChoosePlayers(player, self.cost_data, 1, 1,
    "#tyt_hc__canmou-choose:::"..data.card:toLogString(), self.name, true, false, "addandcanceltarget_tip", AimGroup:getAllTargets(data.tos))
    if #to > 0 then
      self.cost_data = {tos = to}
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if table.contains(AimGroup:getAllTargets(data.tos), self.cost_data.tos[1]) then
      room:addPlayerMark(player, "tyt_hc__canmou-cancel-turn")
      AimGroup:cancelTarget(data, self.cost_data.tos[1])
      return self.cost_data.tos[1] == target.id
    else
      room:addPlayerMark(player, "tyt_hc__canmou-add-turn")
      AimGroup:addTargets(room, data, self.cost_data.tos[1])
    end
  end,
}
local congjianx = fk.CreateTriggerSkill{
  name = "tyt_hc__congjianx",
  events = {fk.TargetConfirming},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and target ~= player and data.card:isCommonTrick() and data.card.trueName ~= "threaten_emperor" and
      U.isOnlyTarget(target, data, event) and table.contains(player.room:getUseExtraTargets(data, true, true), player.id) and
      table.every(player.room:getOtherPlayers(target), function (p) return target.hp >= p.hp end)
  end,
  on_cost = function(self, event, target, player, data)
    return player.room:askForSkillInvoke(player, self.name, data, "#congjianx-invoke:::"..data.card:toLogString())
  end,
  on_use = function(self, event, target, player, data)
    local targets = {player.id}
    AimGroup:addTargets(player.room, data, targets)
    data.extra_data = data.extra_data or {}
    data.extra_data.tyt_hc__congjianx = data.extra_data.tyt_hc__congjianx or {}
    table.insert(data.extra_data.tyt_hc__congjianx, player.id)
  end,
}

local congjianx_delay = fk.CreateTriggerSkill{
  name = "#tyt_hc__congjianx_delay",
  events = {fk.CardUseFinished},
  anim_type = "drawcard",
  can_trigger = function(self, event, target, player, data)
    return not player.dead and data.damageDealt and data.damageDealt[player.id] and
    data.extra_data and data.extra_data.tyt_hc__congjianx and table.contains(data.extra_data.tyt_hc__congjianx, player.id)
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    player:broadcastSkillInvoke(congjianx.name)
    player:drawCards(2, congjianx.name)
  end,
}

congjianx:addRelatedSkill(congjianx_delay)
xinchang:addSkill(canmou)
xinchang:addSkill(congjianx)
Fk:loadTranslationTable{
  ["tyt_hc_heg__n_xinchang"] = "辛敞",
  ["#tyt_hc_heg__n_xinchang"] = "英鉴中铭",
  ["illustrator:tyt_hc_heg__n_xinchang"] = "君桓文化",
  ["tyt_hc__canmou"] = "参谋",
  [":tyt_hc__canmou"] = "每回合各限一次，当手牌数全场最多的角色使用普通锦囊牌指定目标时，你可以为此锦囊牌增加一个额外目标或取消一个目标（目标数至少为1）。",
  ["tyt_hc__congjianx"] = "从鉴",
  [":tyt_hc__congjianx"] = "当体力值最高的其他角色成为普通锦囊牌的唯一目标时，你可以也成为此牌目标，此牌结算后，若此牌对你造成伤害，你摸两张牌。",
  ["#tyt_hc__canmou-choose"] = "参谋：你可以为%arg增加/减少一个目标",
  ["#tyt_hc__congjianx-invoke"] = "从鉴：你可以成为此%arg的额外目标，若此牌对你造成伤害，你摸两张牌",
  ["#tyt_hc__congjianx_delay"] = "从鉴",

  ["$tyt_hc__canmou1"] = "兢兢业业，竭心筹划。",
  ["$tyt_hc__canmou2"] = "欲设此法，计谋二人。",
  ["$tyt_hc__congjianx1"] = "为人臣属，安可不随？",
  ["$tyt_hc__congjianx2"] = "主公有难，吾当从之。",
  ["~tyt_hc_heg__n_xinchang"] = "宪英，救我！",
}

return extension